jQuery in Action
298
CHAPTER 9
Prominent, powerful, and practical plugins
Exercise 2--Click Test Subject 1 again. This toggles the
matched
class,
removing it from the element. The element returns to its original appear-
ance, and the mismatch handler is triggered because the element no
longer matches the selector, resulting in a Console message to that effect.
ance, and the mismatch handler is triggered because the element no
longer matches the selector, resulting in a Console message to that effect.
Exercise 3--Click the Add New Test Subject button. A new test subject
<div>
element is added to the page. Because this element is created with the class
of
of
testSubject
, it now matches the selector used to establish the proactive
click handler that toggles the
matched
class. This triggers Live Query to
automatically bind the click handler to this new element (the code to add
this element doesn't bind any handlers to the newly created element). To
test this supposition, click the newly created Test Subject 2. We see that it
changes rendition and that a match handler has been called on its behalf,
proving that the click handler for toggling the
this element doesn't bind any handlers to the newly created element). To
test this supposition, click the newly created Test Subject 2. We see that it
changes rendition and that a match handler has been called on its behalf,
proving that the click handler for toggling the
matched
class of the element
was automatically added to the newly created element. See the evidence in
figure 9.9.
figure 9.9.
Figure 9.8
The addition of the
matched
class to the test subject triggers
a change in rendition, as well as
the established match handler.
a change in rendition, as well as
the established match handler.
Figure 9.9
The fact that the newly added Test
Subject 2 reacts to clicks in the
same way as Test Subject 1 proves
that Live Query has automatically
added the click handler, as well as
the match and mismatch handlers,
to the newly created element.
Subject 2 reacts to clicks in the
same way as Test Subject 1 proves
that Live Query has automatically
added the click handler, as well as
the match and mismatch handlers,
to the newly created element.