How to debug JavaScript/jQuery event bindings with Firebug?

jQueryWeb DevelopmentFront End Technology

Let’s say an event handler is attached to your element. For example,

$('#foo').click(function() { console.log('clicked!') });

Then you can debug it like this:

For jQuery 1.3.x

var cEvent = $('#foo').data("events").click;
jQuery.each(cEvent, function(key, value) {
   console.log(value)
})

For jQuery 1.4.x

var cEvent = $('#foo').data("events").click;
jQuery.each(cEvent, function(key, handlerObj) {
    console.log(handlerObj.handler)
})

 For jQuery 1.8.x+

var cEvents = $._data($('#foo')[0], "events").click;
jQuery.each(cEvents, function(key, handlerObj) {
  console.log(handlerObj.handler)
})
raja
Published on 20-Dec-2017 12:13:54
Advertisements