11.12.2012 Views

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

JavaScript 2.0-The Complete Reference, Second ... - freecodingtutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

document.getElementById('myText').removeEventListener("mouseover",<br />

changeColor, true);<br />

We‘ll see some specific examples using the addEventListener() later on in the chapter.<br />

Event Objects<br />

As previously mentioned, browsers supporting DOM2 Events pass an Event object as an<br />

argument to handlers. This object contains extra information about the event that occurred, and<br />

is in fact quite similar to the Event objects of the proprietary models. <strong>The</strong> exact properties of<br />

this object depend on the event that occurred, but all Event objects have the read-only<br />

properties listed in Table 11-10.<br />

Table 11-10: Properties Common to All Event Objects<br />

Read-Only Property Description<br />

>bubbles Boolean indicating whether the event bubbles<br />

>cancelable Boolean indicating whether the event can be canceled<br />

>currentTarget Node whose handler is currently executing (i.e., the node the<br />

handler<br />

is bound to)<br />

>eventPhase Numeric value indicating the current phase of the event flow (1<br />

for capture, 2 if at the target, 3 for bubble)<br />

>type String indicating the type of the event (such as "click")<br />

>target Node to which the event was originally dispatched (i.e., the<br />

node at which the event occurred)<br />

Note You can use the symbolic constants Event.CAPTURING_PHASE, Event.AT_TARGET,<br />

and Event.BUBBLING_PHASE instead of the numeric values 1, 2, and 3 when<br />

examining the eventPhase property.<br />

We list the properties specific to each event in the following sections as we discuss the different<br />

kinds of events DOM2-supporting browsers enable you to handle.<br />

Mouse Events<br />

<strong>The</strong> mouse events defined by DOM2 are those from (X)HTML. <strong>The</strong>y‘re listed in Table 11-11.<br />

Since, under DOM2, not all events include a bubbling phase and all default actions can be<br />

canceled, Table 11-11 also lists these behaviors for each event.<br />

Table 11-11: Mouse-Related Events Supported Under DOM2 Events<br />

Event Bubbles? Cancelable?<br />

click Yes Yes<br />

mousedown Yes Yes<br />

mouseup Yes Yes<br />

mouseover Yes Yes<br />

mousemove Yes No<br />

mouseout Yes Yes<br />

When a mouse event occurs, the browser fills the Event object with the extra information<br />

shown in Table 11-12.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!