I bind two event handlers on this link:
<a href='#' id='elm'>Show Alert</a>
JavaScript:
$(function() { $('#elm').click(_f); $('#elm').mouseover(_m); }); function _f(){alert('clicked');} function _m(){alert('mouse over');}
Is there any way to get a list of all events bound on an element, in this case on element with id="elm"
?
All you have to do is press F12 to open the developer tools, select the element in the HTML DOM that you want to investigate, on the right side of the window you will see an option called Event Listeners.
bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to . bind() occurs.
The jQuery bind() event is used to attach one or more event handlers for selected elements from a set of elements. It specifies a function to run when the event occurs. It is generally used together with other events of jQuery. Syntax: $(selector).
In jQuery, you can use the . length property to check if an element exists. if the element exists, the length property will return the total number of the matched elements.
In modern versions of jQuery, you would use the $._data
method to find any events attached by jQuery to the element in question. Note, this is an internal-use only method:
// Bind up a couple of event handlers $("#foo").on({ click: function(){ alert("Hello") }, mouseout: function(){ alert("World") } }); // Lookup events for this particular Element $._data( $("#foo")[0], "events" );
The result from $._data
will be an object that contains both of the events we set (pictured below with the mouseout
property expanded):
Then in Chrome, you may right click the handler function and click "view function definition" to show you the exact spot where it is defined in your code.
General case:
Sources
tabEvent Listener Breakpoints
, and expand treeSimilarly, you can:
Inspect element
"event listeners
'.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With