How to show jQuery event handler on element

Updated . Posted . Visible to the public.

Chrome gives you the currently selected element in the inspector with $0. If you select a button in the DOM you can set and inspect the event handler with the following two code lines:

$($0).on('click', function() { console.log('Hello') })
jQuery._data($0, "events").click[0].handler
// => "function () { console.log('Hello') }"

This is useful for debugging.

Last edit
Arne Hartherz
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2016-12-15 14:15)