1

When using jQuery's unbind, is there a way to see what functions will no longer be executed when that event is triggered?

For example:

var handler = function() {
  alert('The quick brown fox jumps over the lazy dog.');
};
$('#foo').bind('click', handler);
$('#foo').unbind('click');

Is something returned that will let me know that handler was a function that was removed in the unbind?

wkm
  • 1,764
  • 6
  • 24
  • 40
  • *"Is something returned that will let me know that handler was a function that was removed in the unbind?"* no. And there is no officially documented way of finding said events handlers given an element either. – Kevin B Jul 24 '13 at 17:26
  • 1
    Nope, there is nothing telling you what event handlers where removed, you'd have to make something like that yourself it you need it. As a sidenote you should probably be using `on()` and `off()` now, even if the old bind/unbind still works. – adeneo Jul 24 '13 at 17:26
  • 1
    Can you elaborate on why you need to know that? There might be another way to solve your underlying problem. – Frédéric Hamidi Jul 24 '13 at 17:27
  • 2
    if your ultimate aim is to remove the handler function alone, try `$('#foo').unbind('click', handler);` – krishwader Jul 24 '13 at 17:30
  • My goal is to unbind a specific function temporarily and them bind it again at a later point. Problem is the function name is out of my control and could change. – wkm Jul 24 '13 at 22:02
  • @KevinB if you want to pose your comment as an answer, I can mark it as the accepted answer. – wkm Aug 13 '13 at 02:28

2 Answers2

1

I do not know exactly what you want to do but you could try to figure out which event handlers you have attached to the element before calling unbind

Please take a look at this question
Can I find events bound on an element with jQuery?

Community
  • 1
  • 1
svillamayor
  • 546
  • 3
  • 7
1

Is something returned that will let me know that handler was a function that was removed in the unbind?

No. And there is no officially documented way of finding said event's handlers given an element either.

There is an unofficial way of doing it, however it's syntax has changed over the years and is subject to change again (or be removed completely) at any time.

jQuery._data( elem, "events" );
Kevin B
  • 94,570
  • 16
  • 163
  • 180