# Click event on a trace

**URL:** <https://community.plotly.com/t/click-event-on-a-trace/9470>\
**Category:** plotly.js\
**Created:** [April 6, 2018, 8:07am UTC](https://community.plotly.com/t/click-event-on-a-trace/9470 "2018-04-06T08:07:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertrand](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@bertrand](https://community.plotly.com/u/bertrand)\
**Post date:** [April 6, 2018, 8:07am UTC](https://community.plotly.com/t/click-event-on-a-trace/9470/1 "2018-04-06T08:07:30Z")

</div>

Hello everyone,  
i would like add an event when i click on a trace.  
for exemple when i click on a trace, i show an alert “you click on trace X”.

Thanks everyone.

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [April 6, 2018, 1:36pm UTC](https://community.plotly.com/t/click-event-on-a-trace/9470/2 "2018-04-06T13:36:36Z")

</div>

```auto
var gd = document.getElementById('graph')
Plotly.newPlot(gd, [], {})
gd.on('plotly_click', () => {})

```

should do the trick.

---

<div class="post-metadata">

**Author:** ![bertrand](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@bertrand](https://community.plotly.com/u/bertrand)\
**Post date:** [April 6, 2018, 1:47pm UTC](https://community.plotly.com/t/click-event-on-a-trace/9470/3 "2018-04-06T13:47:43Z")

</div>

yes but this it’s if i click on a point .

here i would like that if i click on red trace there an alert but not on black point  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/a/a247565d294add849336bb637bee9153ff1519c5.png)

---

<div class="post-metadata">

**Author:** ![etienne](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/etienne/32/17_2.png) [@etienne](https://community.plotly.com/u/etienne)\
**Post date:** [April 6, 2018, 8:28pm UTC](https://community.plotly.com/t/click-event-on-a-trace/9470/4 "2018-04-06T20:28:03Z")

</div>

Ha, we don’t expose a way to that at the moment.

You can subscribe to [https://github.com/plotly/plotly.js/issues/145](https://github.com/plotly/plotly.js/issues/145) for the most up-to-date development info.

---

<div class="post-metadata">

**Author:** ![bertrand](https://avatars.discourse-cdn.com/v4/letter/b/a88e4f/32.png) [@bertrand](https://community.plotly.com/u/bertrand)\
**Post date:** [April 7, 2018, 8:04am UTC](https://community.plotly.com/t/click-event-on-a-trace/9470/5 "2018-04-07T08:04:39Z")

</div>

Ok, thank for your help 🙂
