0

I have an element <div class='graph'> and I try to associate an onClick event with it. There are some dynamic loading process on top of this element, but I am not sure what the event handler does the process load exactly.

For example, after open the web page, I use highchart to plot a chart on <div class='graph'> and then I tried to add an event handler $('.graph').on('click',function(){//to show some text when click the <div>}, but unfortunately, this does not work (the function never execute when I click over the element). The only think I could image is that the highchart added some 'click' event over '.graph'. So when I add another 'click' event, it will not work as expected.

My question is:

  1. how could I know what's the first 'click' event (by console.log($('.graph').click()) seems not giving me any useful info)?

  2. how should I make my second click successful?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Guifan Li
  • 1,543
  • 5
  • 14
  • 28
  • 1
    `.on()` adds an event listener. An element can have multiple event listeners, and all will be fired. However, maybe the click is disabled with [`pointer-events`](https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events), or another event listener stops the propagation of the event before it reaches your element. – Oriol Jul 05 '15 at 17:42
  • It would be nice to see some source code – Gustaf Gunér Jul 05 '15 at 17:43
  • maybe try to take all event listeners off first with .off() and then put your event listener .on(). – L4zl0w Jul 05 '15 at 17:43
  • @Oriol Thanks for your answer. Maybe it is another event listener stops the propagation. But how could I analysis this? How could I find which event stop the propagation? – Guifan Li Jul 05 '15 at 17:49
  • @L4zl0w Thanks for your answer. I did try to use .off() on '.graph' and then use .on('click',function(){console.log('clicked')}). However, the click event is still not triggered for some reason..... – Guifan Li Jul 05 '15 at 19:04
  • Look at this thread http://stackoverflow.com/questions/446892/how-to-find-event-listeners-on-a-dom-node – L4zl0w Jul 05 '15 at 22:40

1 Answers1

1

In the source code you can find line #9946 (for 4.1.7) - which prevents default method, however, there you won't find stopPropagation() call.

I suggest to use chart.events.click instead.

Paweł Fus
  • 44,795
  • 3
  • 61
  • 77