views:

268

answers:

3

From what I understand livequery is for maintaining your events after DOM changes.

Does not the latest build of jquery already support this?

A: 

jQuery 1.3.2 includes the live() method for bubbled event handling.

Pointy
He's aware of that. He's asking why livequery is still around.
ceejayoz
+5  A: 

Yes, it is still useful. live() only works on certain events, while livequery() can be bound to any event the user's browser provides.

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 like touchstart, touchend, etc.

ceejayoz
A: 

One useful feature that livequery() provides while live() doesn't is the ability to fire a custom function every time a new element is matched (and/or an element 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) for when an element is no longer matched. This provides ultimate flexibility and untold use-cases. For example the following code uses a function based Live Query to implement the jQuery hover helper method and remove it when the element is no longer matched.

$('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'); 
    });
mtyaka