# Plot – Crosshair State / Event Listener

**URL:** <https://talk.observablehq.com/t/plot-crosshair-state-event-listener/8690>\
**Category:** Help\
**Created:** [January 11, 2024, 5:42am UTC](https://talk.observablehq.com/t/plot-crosshair-state-event-listener/8690 "2024-01-11T05:42:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eliot](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/eliot/32/8410_2.png) [@eliot](https://talk.observablehq.com/u/eliot)\
**Post date:** [January 11, 2024, 5:42am UTC](https://talk.observablehq.com/t/plot-crosshair-state-event-listener/8690/1 "2024-01-11T05:42:19Z")

</div>

Is there any way with observable to get the hovered value when using the crosshair, to be displayed in other reactive elements? I’m trying to highlight a point on a map (maplibre, not Plot) depending on what point the observable crosshair is selecting / hovering over on a time series graph. I would use d3.mouse() but it doesn’t track the click action with the crosshair, which keeps the position fixed.

This is the effect I am trying to achieve: [CleanShot 2024-01-10 at 21.43.55 · CleanShot Cloud](https://share.cleanshot.com/d37rY5N1)

Any help appreciated!

---

<div class="post-metadata">

**Author:** ![eliot](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/eliot/32/8410_2.png) [@eliot](https://talk.observablehq.com/u/eliot)\
**Post date:** [January 11, 2024, 5:48am UTC](https://talk.observablehq.com/t/plot-crosshair-state-event-listener/8690/2 "2024-01-11T05:48:37Z")

</div>

Actually, the docs kind of answer my own question! (Just not in the same section) Apparently, you can just [add an event listener](https://observablehq.com/plot/interactions/pointer).

```auto
chart.addEventListener("input", (event) => {
  console.log(chart.value);
});

```

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [January 11, 2024, 11:20am UTC](https://talk.observablehq.com/t/plot-crosshair-state-event-listener/8690/3 "2024-01-11T11:20:03Z")

</div>

You can prefix your cell name with `viewof`:

```js
viewof chart = // ...

```

and access the value in other cells through

```auto
chart

```

Here is a brief intro:

> **[What has viewof ever done for us?!](https://observablehq.com/@mootari/what-has-viewof-ever-done-for-us)**
>
> A short introduction to \`viewof\`, in response to this post. \`viewof\` is an Observable macro (i.e., a "magic word") that allows you to create user interfaces for your values. Observable cells by themselves are rather boring: they can only store...
