HTML and CSS Reference
In-Depth Information
Figure 15.37 Further bubbling stops after a user clicks the link.
15.9 Event Listeners with the W3C Model
15.9.1 Adding an Event
The addEventListener Method. The W3C event model adds the addEventLis-
tener() method, which registers a single event listener on a document, a window, a DOM
node or X(HTML), or an Ajax XMLHttpRequest (see Chapter 18, “An Introduction to
Ajax (with JSON)”). This method takes three arguments:
1. The event type to listen for (mouseover, click, etc.).
2. A function to be executed when the event is fired.
3. A Boolean (called useCapture ) of true or false to specify the event propagation
type: true to turn on event capturing and false to turn on event bubbling (the
most cross-browser-compliant way is false).
FORMAT
target.addEventListener(type, listener, useCapture);
EXAMPLE
var div1 = document.getElementById("mydiv");
div1.addEventListener('click',sayWelcome,false);
 
 
 
Search WWH ::




Custom Search