HTML and CSS Reference
In-Depth Information
window.onload=function(){
document.getElementById("bdy").style.backgroundColor="lightgreen";
}
15.8.3 The DOM Way
The W3C Dom Level 2 standardized the event model to solve compatibility problems
between browsers. Most modern browsers (Mozilla, Opera, Safari, Chrome and Kon-
queror) are W3C compliant, except Microsoft Internet Explorer which has its own
model.
DOM objects can be registered as event listeners. This feature can be used to assign
multiple handlers for a given event which is the main difference from the traditional
model. To achieve this, event listeners are no longer stored as HTML attribute values but
are registered with an event listener method.
The W3C supports event bubbling described below, but has a useCapture option can
be used to specify that the handler should be called in the capture phase. Browser).
15.8.4 Bubbling and Capturing
When we discussed events in Chapter 13 we introduced capturing and bubbling to
describe the flow of events in a program. The way that the events are captured differs
in different browsers. In Mozilla Firefox, for example, the event comes to life at the
window level and is sent down the tree of nodes until it finally reaches the target
object for which it was intended, whereas with Internet Explorer the event springs to
life for the target it was intended to affect, and then sends information about the event
bubbling back up the chain of nodes. Handling the way events propagate has been
another browser compatibility issue. The W3C DOM Level 2 allows the DOM nodes
to handle events with a combination of these methods, but defaults to the bubble up
propagation model.
<body>
<body>
<div>
<div>
<p>
<p>
<a>
<a>
Capturing
Bubbling
Figure 15.33 Event capturing and bubbling.
 
 
 
 
Search WWH ::




Custom Search