tags:

views:

1801

answers:

2

When the page is done loading I call a function which puts the hover event on $('a.tooltip'). When I want to unbind this event I do the following:

   $('a.tooltip').unbind('mouseover mouseout');

That works! However when I want rebind the hover event and I call the function that was first loaded at document ready again, it doesn't rebind the hover helper. How can I rebind it?

Thank you,

Ice

+3  A: 

Are you sure the unbinding is working correctly? In my experience, .hover() does rebind properly, but I have had to use this unbind syntax:

$(this).unbind('mouseenter').unbind('mouseleave');

When I tried putting both events into one unbind(), it only unbound one of them.

I wonder if that's happening for you? (Or if the choice of mouseover vs mouseenter, etc, matters?)

Update

According to quirksmode.org, mouseenter and mouseleave are IE-specific events, but as Jimmy pointed out in the comments, jQuery implements them for other browsers as well.

Nathan Long
Thank you!! It definitly matters because this just fixed it. I am now able to .hover() again and rebinds it.
Great! Would you mind marking my answer as accepted, then?
Nathan Long
I believe jquery implements mouseenter and mouseleave
Jimmy
You're right - it's in the jQuery source.
Nathan Long
A: 

I found that when I use the bind method, things can be a bit fussy. You might want to try using the hover(over, out) function as such:

 $(this).hover( 
    function() {
       if (okayToHover) { dowhatever; } 
    },
    function() {
       if (okayToUnhover) { undowhatever; }
    });

I know it seems a bit roundabout, but I find that the hover function gives me a bit more control over what's going on, and it seems to work a bit better for whatever reason. That's just in my experience though...

Plan B
Behind the scenes, jQuery's .hover() is just binding traditional JS mouse events. If for some reason you wanted to disable and later re-enable hover functionality, how would you do it?
Nathan Long