15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

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.

66 <strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Listing 15-25 (continued)<br />

alert(“This browser version does not support the feature.”)<br />

}<br />

}<br />

<br />

<br />

<br />

fireEvent() Method<br />

<br />

This is a paragraph (with a nested SPAN)<br />

that receives click events.<br />

<br />

Control Panel<br />

<br />

Cancel event bubbling.<br />

<br />

<br />

<br />

<br />

<br />

<br />

fireEvent(“eventType”[, eventObjectRef])<br />

elementObject.fireEvent()<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓<br />

Example<br />

The small laboratory of Listing 15-26 enables you to explore the possibilities of<br />

the IE5.5 fireEvent() method while reinforcing event bubbling concepts in IE.<br />

Three nested element objects are assigned separate onClick event handlers (via<br />

the init() function invoked after the page loads — although you can also set these<br />

event handlers via onClick attributes in the tags). Each handler displays an alert<br />

whose content reveals which object’s event handler was triggered and the tag name<br />

and ID of the object that received the event. The default behavior of the page is to<br />

allow event bubbling, but a checkbox enables you to turn off bubbling.<br />

After you load the page, click the italic segment (a nested SPAN element) to<br />

receive a series of three alert boxes. The first advises you that the SPAN element’s<br />

onClick event handler is processing the event and that the SPAN element (whose ID

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

Saved successfully!

Ooh no, something went wrong!