HTML and CSS Reference
EXPLANATION ( CONTINUED )
When the click event is triggered, the function called iam() is sent to the event
object and is received as a parameter. It contains data about the event, in this case
the click event and the object that was clicked. (See Chapter 13.)
The cancelBubble property (Internet Explorer) returns or sets a Boolean that rep-
resents whether the current event should bubble up the hierarchy of event han-
dlers. If set to true , event bubbling is canceled, preventing the next event handler
in the hierarchy from receiving the event.
The stopPropagation() method is used to prevent further propagation of an event
during event flow. If this method is called by any event listener or handler, the event
will stop bubbling up the DOM tree. The event will complete dispatch to all listen-
ers on the current EventTarget before event flow stops. This method may be used
during any stage of event flow so if you click the link, the bubbling will stop there
or if you click on the div element, it will stop at that point and go no further. See
An id attribute is assigned to the body element.
Two paragraphs within the div container are also given id s.
Within the second paragraph, an id is assigned to the < a> tag. If bubbling starts at
the link, it will propagate upward through its ancestor tree to the all of those ele-
ments that are waiting for a click event to happen, but in this example the bub-
bling will stop right away because it is being canceled when the iam() function is
called. See the results in Figures 15.36 and 15.37.
Figure 15.36 The initial page before clicking on the link.