Protiviti / SharePoint Blog

SharePoint Blog

January 18
How to Find Event Functions for DOM Elements

​Sometimes when debugging website javascript code it isn’t immediately apparent what exactly is happening or even where to start looking.  Event functions can be buried in numerous script files and bound dynamically so tracking them down is a tedious task.  Below is a trick to figure out exactly what event is firing on any DOM element with jQuery.  For the example in this post I have made a simple resize function on the “window” element.

First we need to get all of the events on the DOM element with jQuery._data(element, ‘events’).  Then from this we can get out events (click, hover, etc.).  


 
Events will be arranged by type in an array.  We get the first click event by doing “.resize[0]”.  From this we get the actual function call with “.handler”.  Using Chrome as the browser will give you the function at this point:

If using another browser like Firefox we need another step.  We can put the whole statement into an alert to display the function’s contents:



Quick Launch


© Protiviti 2017. All rights reserved.   |   Privacy Policy