04.11.2015 Views

javascript

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12: Events<br />

Property/Method Type Read/Write Description<br />

bubbles Boolean Read only Indicates if the event bubbles.<br />

cancelable Boolean Read only Indicates if the default behavior of the event<br />

can be canceled.<br />

currentTarget Element Read only The element whose event handler is<br />

currently handling the event.<br />

detail Integer Read only Extra information related to the event.<br />

eventPhase Integer Read only The phase during which the event handler<br />

is being called: 1 for the capturing phase, 2<br />

for “ at target, ” and 3 for bubbling.<br />

preventDefault() Function Read only Cancels the default behavior for the event.<br />

If cancelable is true , this method can be<br />

used.<br />

stopPropagation() Function Read only Cancels any further event capturing or<br />

event bubbling. If bubbles is true , this<br />

method can be used.<br />

target Element Read only The target of the event.<br />

type String Read only The type of event that was fired.<br />

view AbstractView Read only The abstract view associated with the event.<br />

This is equal to the window object in which<br />

the event occurred.<br />

Inside an event handler, the this object is always equal to the value of currentTarget , whereas<br />

target contains only the actual target of the event. If the event handler is assigned directly onto the<br />

intended target, then this , currentTarget , and target all have the same value. Here is an example:<br />

var btn = document.getElementById(“myBtn”);<br />

btn.onclick = function(event){<br />

alert(event.currentTarget === this); //true<br />

alert(event.target === this);<br />

//true<br />

};<br />

This code examines the values of currentTarget and target relative to this . Since the target of the<br />

click event is the button, all three are equal. If the event handler existed on a parent node of the button,<br />

such as document.body , the values would be different. Consider the following example:<br />

document.body.onclick = function(event){<br />

alert(event.currentTarget === document.body); //true<br />

alert(this === document.body);<br />

//true<br />

alert(event.target === document.getElementById(“myBtn”)); //true<br />

};<br />

376

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

Saved successfully!

Ooh no, something went wrong!