15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

2<br />

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

✦ Follow the steps for the disabled property to see how form controls can be<br />

disabled in IE4+ and NN6. IE5.5 lets you disable any element on the page, as<br />

you can witness in real time when you follow the example steps.<br />

✦ Long-time IE scripters know the powers of the innerHTML and innerText<br />

properties. Listing 15-11 solidifies by example the precise differences between<br />

the two related properties. Only one of these properties, innerHTML, is<br />

implemented in NN6.<br />

✦ Grasping the details of properties that govern element positions and dimensions<br />

is not easy, as noted in the <strong>JavaScript</strong> <strong>Bible</strong> text. But you can work through<br />

the examples of the client-, offset-, and scroll-related properties for IE4+ and the<br />

offset-related properties in NN6 to help you visualize what these properties control.<br />

If you are scripting cross-browser applications, be sure to work through the<br />

offset-related properties in both browsers to compare the results.<br />

✦ Compare the IE5+ attachEvent() method and NN6 addEventListener()<br />

method for modern ways to assign event handlers to element objects.<br />

Although the method names are different, the two work identically.<br />

✦ Observe how the getAttribute() method returns an object’s property value<br />

when the property name is a string and the name is the same as an assigned<br />

element attribute name. The getAttribute() method is the prescribed way<br />

to retrieve property values according to the W3C DOM.<br />

✦ You can see how the getElementsByTagName() method returns an array of<br />

nested elements with a particular tag. This is a great way, for example, to get a<br />

one-dimensional array of all cells within a table.<br />

✦ Spend time comparing how the various insert- and replace-related methods<br />

operate from different points of view. In the IE world, most operate on the current<br />

element; in the W3C DOM world, the methods operate on child nodes of<br />

the current element.<br />

✦ For IE5+/Windows, check out the way dynamic properties are managed<br />

through the getExpression(), setExpression(), and recalc() methods.<br />

Listing 15-32 demonstrates a neat graphical clock that employs these methods.<br />

✦ IE5+/Windows provides a number of event handlers, such as onBeforeCopy,<br />

onBeforePaste, onCopy, onCut, and onPaste that let scripts manage the<br />

specific information preserved in the clipboard. These event handlers can<br />

also be used with the onContextMenu event handler to facilitate custom<br />

context menus.<br />

✦ Another set of IE5+/Windows event handlers provides excellent control over<br />

user dragging and dropping of elements on a page. Listing 15-37 is particularly<br />

interesting in this regard.<br />

✦ Listing 15-41 shows a cross-browser laboratory for understanding the three<br />

keyboard events and how to get key and character information from the event.<br />

You see event-handling that works with IE4+, NN4, and NN6 event models.<br />

✦ Numerous mouse-related events belong to all HTML elements. Listings 15-42<br />

and 15-43 demonstrate simplified image swapping and element dragging.

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

Saved successfully!

Ooh no, something went wrong!