Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see the event that is attached to an html element?

Hello I am a new programmer and still learning. This is the code that I am trying to figure out:

<div id="buy" class="buy button">Buy</div> 

When I click on the div (button), some javascript code is executed but I don't know were it is. How can I tell what function is fired when click happens? Some how a listener is attached to this element

like image 890
Vaso A. Avatar asked Aug 06 '12 17:08

Vaso A.


People also ask

How do you find the event listener of an element?

Right-click on the search icon button and choose “inspect” to open the Chrome developer tools. Once the dev tools are open, switch to the “Event Listeners” tab and you will see all the event listeners bound to the element. You can expand any event listener by clicking the right-pointing arrowhead.

How do you capture an event in HTML?

For event capturing, we set the handler capture option to true: elem. addEventListener(event, handler, true) . By default, it is set to bubbling: false . In the example below, we add click event handlers on every HTML element using JavaScript for loop.

How do I know which element was clicked in HTML?

To check if an element was clicked, add a click event listener to the element, e.g. button. addEventListener('click', function handleClick() {}) . The click event is dispatched every time the element is clicked. Here is the HTML for the examples in this article.


2 Answers

In Google chrome's developer tools (click the wrench icon >Tools>Developer tools), select the element in the Elements tab, on the right open the 'Event Listeners' panel you'll will see all events

like image 132
yoelp Avatar answered Oct 19 '22 12:10

yoelp


If you use Firefox and Firebug you can try installing FireQuery. It will make it so you can see the handlers bound by jQuery. http://firequery.binaryage.com/

like image 42
aknosis Avatar answered Oct 19 '22 12:10

aknosis