---
title: viewer2d.click
slug: viewer-2d/events/viewer2d-click
docTags: 
createdAt: 2024-02-21T17:04:37.158Z
---

Invoked when the user clicks inside the viewer.

## Example

::codepen{url="https://codepen.io/Catenda/embed/MWMBgeJ"}

## Usage

:::CodeblockTabs
```javascript
const onClick = function (event) {
  const { intersects } = event;
  console.log("viewer2d.click", "intersects:", intersects);
};

viewer2d.addEventListener("viewer2d.click", onClick);
```

jQuery

```javascript
const onClick = function (event, location, objectId) {
  console.log("viewer2d.click", "location:", location, "objectId:", objectId);
};

$("#viewer-2d").on("viewer2d.click", onClick);
```
:::

## Parameters

### onClick

:::::Tabs
:::Tab{title="JS"}
Function called when the user clicks inside the viewer.

| **Type**                  |
| ------------------------- |
| `(event: Object) => Void` |

**event**

| **Name**         | **Type** | **Description**                              |
| ---------------- | -------- | -------------------------------------------- |
| `intersects`     | Object   | Object below the cursor, `undefined` if none |
| `preventDefault` | Function | Disable space selection for click event      |
| `srcEvent`       | Object   | Original DOM event                           |

**intersects**

| **Name**   | **Type**                                | **Description**                         |
| ---------- | --------------------------------------- | --------------------------------------- |
| `objectId` | String                                  | Id of the object                        |
| `point`    | [Vector3](docId\:gQdK6kHl9IuzRieGxVDD0) | Intersection point of the object        |
| `normal`   | [Vector3](docId\:gQdK6kHl9IuzRieGxVDD0) | Normal vector at the intersection point |
:::

::::Tab{title="jQuery"}
Function called when the user clicks inside the viewer.

:::hint{type="info"}
Returning false from the `onClick` function will disable object selection for click event
:::

| **Type**                                                              |
| --------------------------------------------------------------------- |
| `(event: Object, location: Object, objectId: String) => Boolean/Void` |

**event**

[jQuery.Event](https://api.jquery.com/category/events/event-object/)

**location**

Coordinates of the position clicked.

| **Name** | **Type** | **Description**                            |
| -------- | -------- | ------------------------------------------ |
| `x`      | Number   | X coordinate of position clicked in pixels |
| `y`      | Number   | Y coordinate of position clicked in pixels |
| `z`      | Number   | Height of the last storey shown in meters  |

**objectId**

Id of the object clicked, `undefined` if no object under cursor
::::
:::::

