Before jQuery’s native live() and delegate() functions came into being, the default for handling binding on late generated DOM elements was to make use of the excellent Brandon Aaron plugin LiveQuery (otherwise known as Live Query). Today we look at how one handles the hover event using a livequery declaration.
Now the standard way of using livequery is to simple attach the function call to the targeted element as such:
$('.mylink').livequery('click',function(){ alert('clicked'); });
However, because the hover event contains an implicit combination of the mouseover and mouseout functions, the livequery declaration for hover events looks considerably different:
$('.mylink').livequery(function(){ $(this).hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); }); }, function() { $(this).unbind('mouseover').unbind('mouseout'); });
And that’s is pretty much it. As you can see, you declare a standard full hover jquery function declaration as the first argument for the livequery function call. The second function call deals with the unbinding of the previously bound argument.
Not quite intuitive from the first glance, but it works like a bomb. In other words, nifty.
Related Link: http://brandonaaron.net/code/livequery/docs
You might also enjoy:
-
Sometimes you just don't want to use the good old anchor tag and want to use a tag instead, but at the same time, you want people who mouse-over your span ...
-
Flot is a fantastic jQuery-driven graphing engine that is extremely flexible and capable of producing some wonderfully looking and interactive graphs. To ...
-
I’ve mentioned the wonderful jQuery plugin DataTables a number of times before, the awesome little trick that instantly transforms any HTML table fed to it ...
-
This seems a little silly to even mention here, but some people don't now how to actually trigger events for which they've sculpted all that nifty jQuery co ...
-
As it has quickly become apparent on this site, my two current favourites in the land of web development is the fantastic jQuery javascript library and the ...