264Part IIIDocument Objects ReferenceRelated Items:readyStateproperty; removeBehavior()method; behaviors (Chapter (Make web site)
264Part IIIDocument Objects ReferenceRelated Items:readyStateproperty; removeBehavior()method; behaviors (Chapter 48 onthe CD-ROM). addEventListener( eventType , listenerFunc, useCapture) removeEventListener( eventType , listenerFunc, useCapture) Returns:Nothing. Compatibility:WinIE-, MacIE-, NN6+, Moz1+, Safari1+ The W3C DOM s event mechanism accommodates both event bubbling and trickling (seeChapter 25). While the new mechanism supports the long-standing notion of binding an eventto an element by way of HTML attributes (for example, the old onclickevent handler), itencourages binding events by registering an event listener with an element. (In browsers thatsupport the W3C event model, other ways of binding events such as event handlerattributes are internally converted to registered events.) To tell the DOM that an element should listen for a particular kind of event, use theaddEventListener()method on the element object. The method requires three parameters. The first is a string version of the event type for which the element should listen. Event typestrings do not include the well-used on prefix of event handlers. Instead, the names consistonly of the event and are usually in all lowercase (except for some special system-wide eventspreceded by DOM). Table 15-7 shows all the events recognized by the W3C DOM specification(including some new DOM ones that are not yet implemented in browsers). Table 15-7: W3C DOM Event Listener Typesaborterrorblurfocuschangeloadclickmousedown DOMActivatemousemove DOMAttrModifiedmouseoutDOMCharacterDataModifiedmouseoverDOMFocusIn mouseupDOMFocusOut resetDOMNodeInsertedresizeDOMNodeInsertedIntoDocumentscrollDOMNodeRemovedselectDOMNodeRemovedFromDocumentsubmitDOMSubtreeModifidunloadNote that the event types specified in the DOM Level 2 are more limited than the wide rangeof events defined in IE4+. Also, the W3C temporarily tabled the issue of keyboard events untilDOM Level 3. Fortunately, most W3C-compatible browsers implement keyboard events in afashion that likely will appear as part of the W3C DOM Level 3. The second parameter of the addEventListener()method is a reference to the JavaScriptfunction to be invoked. This is the same form used to assign a function to an event propertyof an object (for example, objReference.onclick = someFunction), and it should notbe aquoted string. This approach also means that you cannot specify parameters in the functionelementObject.addEventListener()