ptg16476052
Modifying Content on the Page 517
18
As you can see, the event binding is slightly different here. Instead of using the click()
method, I’ve used the on() method with document as the selector. This indicates that I
want to monitor changes to the page and perform the event binding that follows any time
an element matching the selector (the second argument) is added. The first argument is
the name of the event to bind—it’s the name of the event to be bound, placed in quota-
tion marks. The second argument is the selector to match. The third is the event handler
as it would normally be written. The on() method is one of the most powerful features of
jQuery because it enables you to automatically treat dynamically generated content the
same way you’d treat content that’s on the page at the time that it loads.
Here’s the full source for the page:
<!DOCTYPE html>