On 21/04/2007, at 5:18 PM, Joel Birch wrote:
On 21/04/2007, at 5:14 PM, SiCo wrote:
$('ele').unbind('mouseover').unbind('mouseout');
Unbind each individual event, I don't know why Joel names the
function? Can you have multiple functions?
The code:
$('ele').unbind('mouseover').unbind('mouseout');
...clears all handlers for those events, but if you name the
handler you want to remove then only that functionality is unbound
leaving other functions attached to those events intact. If you do
want to clear all handlers then the aforementioned code is perfect.
Joel.
To clarify, you can do this:
function over1() {
alert("mouseover function 1 fired");
}
function out1() {
alert("mouseout function 1 fired");
}
function over2() {
alert("mouseover function 2 fired");
}
function out2() {
alert("mouseout function 2 fired");
}
$('#ele').hover( over1, out1 );
$('#ele').hover( over2, out2 );
... then hovering the element will fire two alerts on mouseover, and
two alerts on mouseout.
However if you add line at the end:
$('#ele').unbind('mouseover',over2).unbind('mouseout', out2);
... then hovering the element will fire only the alert from the over1
function on mouseover and only the alert from the out1 function on
mouseout.
But if instead of that last line you did this:
$('#ele').unbind('mouseover').unbind('mouseout');
... then nothing at all will fire when the element is hovered.
Joel.