If I bind an event to an element in jQuery, do I always have to unbind it from the exact same element I bound it to? Can I unbind from a child or a parent? I am also using an event namespace – does this have any bearing on the situation?
<div id="id1">
<div id="id2">
<div id="id3">
hello
</div>
</div>
</div>
$("#id2").bind("click.mynamespace", function() { alert("hi!");});
$("#id1").unbind("click.mynamespace"); //will this work?
$("#id3").unbind("click.mynamespace"); //will this work?
It doesn’t seem to be mentioned anywhere in the jQuery documentation.
No, it is not an event and thus does not bubble. All event-related functions will act on exactly the elements in the jQuery object.
If you want this behaviour, simply select all elements:
On a side-note,
.bind()and.unbind()are kind of deprecated as of jQuery 1.7 – better use.on()and.off()instead (same arguments in your case).