If you have the latest version of jquery installed, is livequery still useful?
Yes, this is still useful. live()
works only with certain events, and livequery()
can be attached to any event provided by the user's browser.
http://docs.jquery.com/Events/live
Possible event values:
click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup
Currently not supported:
blur, focus, mouseenter, mouseleave, change, submit
Note that also unsupported are touch events such as touchstart, touchend
etc.
source to share
One useful feature that livequery()
provides when live()
not the ability to run a custom function every time a new item is matched (and / or the item is no longer matched).
From the docs :
Live Query also has the ability to fire a function (callback) when it matches a new element, and another function (callback) when the element is no longer matched. This provides maximum flexibility and unused use cases. For example, the following code uses a Live Query based function to implement the jQuery hover helper method and remove it when the element no longer matches.
$('li')
.livequery(function(){
// use the helper function hover to bind a mouseover and mouseout event
$(this)
.hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
}, function() {
// unbind the mouseover and mouseout events
$(this)
.unbind('mouseover')
.unbind('mouseout');
});
source to share