jQuery in Action

The Live Query Plugin
293
page--including existing elements that might be changed to match the pattern
and newly created elements that match.
When such elements are changed so that they no longer match the selector, han-
dlers established by Live Query are automatically removed from those elements.
The changes that affect whether an element matches the selector pattern or
not hinge on using jQuery methods. If the elements are mucked about with out-
side the realm of jQuery, obviously Live Query loses the hooks it needs to keep
track of the elements. If we absolutely need to make changes outside jQuery's con-
trol, Live Query does have a way to help us deal with that; we'll get to that later.
All of the Live Query behaviors, including event listeners, are established on
elements using the
livequery()
method. The format that establishes proactive
event handlers is as follows:
This form of
livequery()
is called exactly like the jQuery
bind()
command. Like
bind()
, it establishes the handler for all elements in the matched set. But it also auto-
matically establishes the handler on any elements that match the selector pattern at
any time while the page is loaded. It also unbinds the listener from any elements,
including those from the original matched set, that no longer match the pattern.
This is immensely powerful. It allows us to set up the behavior of elements that
match a selector of our choosing once in the ready handler, without having to
worry about keeping track of such things later as elements are changed or added
to the page. How cool is that?
The establishment of event handlers is a special case--a common one, which
is why it gets special attention--of performing actions when elements are
changed (or added) so that they match or no longer match the original selector
pattern. We might like to do a multitude of other things at such points, and Live
Query doesn't disappoint us.
Command syntax: livequery
livequery(event,listener)
Establishes a function as the event handler for the specified event type on all elements in the
matched set and any elements that will match the selector of the matched set at a later point.
Parameters
event
(String) The type of event for which to establish the listener. This is the same
set of events as used with the jQuery bind() command.
listener
(Function) The function to establish as the event listener. The function context
(this) for each invocation is the matched element.
Returns
The wrapped set.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.