Search code examples
livequery

What is a "matched element" in Live Query?


I know, from one of the comments I was reading at Is livequery deprecated, "livequery is dead." However, I need to study it in order to upgrade some legacy code that I received.

I was reading the Live Query official documentation at https://github.com/hazzik/livequery/blob/master/README.md, and it talks about "firing callbacks for matched elements". What is a "matched element"? I understand the concept of events, but I am not sure what a "matched element" is. Matched by whom or by what? They provide the following example:

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

This is the jQuery selector: $('li'). The documentation at https://github.com/hazzik/livequery/blob/master/README.md says that "Live Query fires a function (callback) when it matches a new element." What does it mean to "match an element" in this context? Thank you.


Solution

  • From what I understand, after reading https://github.com/brandonaaron/livequery, using as an example the code in my question, the page is loaded entirely. After that, when a new 'li' element is added to the DOM, that would be a "matched element" because it matches the 'li' element specified in the jQuery selector.