jQuery in Action
294
CHAPTER 9
Prominent, powerful, and practical plugins
9.3.2 Defining match and mismatch listeners
If we want to perform an action (other than binding or unbinding event handlers)
when elements make a transition into or out of the state of matching a particular
selector, we can use another form of the
when elements make a transition into or out of the state of matching a particular
selector, we can use another form of the
livequery()
command.
If we only want to establish the optional mismatch listener, we can't do so by pass-
ing
ing
null
as the first parameter to this method because this causes the second
parameter to be established as the match listener just as if it had been passed as
the first argument. Instead, we pass in a no-op function as the first parameter:
the first argument. Instead, we pass in a no-op function as the first parameter:
$('div.whatever').livequery(
function(){},
function(){ /* mismatch actions go here */ }
);
As with the event listeners established by Live Query, the change causing the tran-
sition into or out of the matched state automatically triggers these functions when
the change is performed by a jQuery method. But what about those times when we
can't use jQuery for such changes?
sition into or out of the matched state automatically triggers these functions when
the change is performed by a jQuery method. But what about those times when we
can't use jQuery for such changes?
9.3.3 Forcing Live Query evaluation
If we effect changes to elements that cause them to transition into or out of the
matched state for Live Query listeners that we've established through means
other than jQuery functions, we can force Live Query to trigger its listeners with a
utility function.
matched state for Live Query listeners that we've established through means
other than jQuery functions, we can force Live Query to trigger its listeners with a
utility function.
Command syntax: livequery
livequery(onmatch,onmismatch)
Establishes callback functions invoked when elements transition into or out of the state of
matching the selector for the matched set.
matching the selector for the matched set.
Parameters
onmatch
(Function) Specifies a function that serves as the match listener. This function
is invoked for any element (established as the function context) that transi-
tions into the matched state. If any existing elements match at the time of
this method call, the function is called immediately for each such element.
is invoked for any element (established as the function context) that transi-
tions into the matched state. If any existing elements match at the time of
this method call, the function is called immediately for each such element.
onmismatch
(Function) Specifies an optional function that serves as the mismatch lis-
tener. This function is invoked for any element (established as the function
context) that transitions out of the matched state. If omitted, no mismatch
listener is established.
tener. This function is invoked for any element (established as the function
context) that transitions out of the matched state. If omitted, no mismatch
listener is established.
Returns
The wrapped set.
The wrapped set.