If you have the latest version of jquery installed, is livequery still useful?

From what I understand, livequery is meant to support your events after the DOM changes.

Doesn't the latest jquery build support this?

+2


source to share


2 answers


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.

+7


source


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

      

+2


source







All Articles