1

Or how do I know whether this below has been run or not:

$target.bind('click',function() {
...
});
user198729
  • 61,774
  • 108
  • 250
  • 348

4 Answers4

0

You can use $._data. For example

$target.bind('click',function() {
...
});

$._data( $target[0], 'events'); // Object {click: Array[1]}
AntouanK
  • 4,880
  • 1
  • 21
  • 26
0

I use the visual event bookmarklet to show me which items have events.

easement
  • 6,119
  • 3
  • 29
  • 36
  • There's also firequery, a plugin for firebug, but it takes up memory so I disabled it. http://firequery.binaryage.com/ – easement Jan 14 '10 at 15:31
0

You can access the jQuery.data object to find out:

$.fn.isBound = function() {
    return this.length && typeof $.data(this[0], 'handle') == 'function' || false;
}

if ($target.isBound()) {
    // $target has events
}

UPDATE: if you want to check for specific types you can look in the events object:

$.fn.isBound = function(type) {
    return this.length && $.data(this[0], 'events')[type] || false;
}

if ($target.isBound('click')) {
    // $target has clickevents
}
David Hellsing
  • 106,495
  • 44
  • 176
  • 212
0

Borrowing from and extending David's example, use this:

if(typeof $('#id').click == 'function') {}
Wally Lawless
  • 7,539
  • 7
  • 37
  • 53