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.

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

notation. IE5 and NN6 understand the W3C standard getElementById() method of<br />

addressing an element. You can enter the following sample statements into the top<br />

text box to view attribute values.<br />

IE4:<br />

document.all.myTable.getAttribute(“width”)<br />

document.all.myTable.getAttribute(“border”)<br />

IE5/NN6:<br />

document.getElementById(“myTable”).getAttribute(“width”)<br />

document.getElementById(“myTable”).getAttribute(“border”)<br />

getAttributeNode(“attributeName”)<br />

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

Compatibility ✓<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to explore the<br />

getAttributeNode() method in NN6. The Results TEXTAREA element provides<br />

several attributes to check out. Because the method returns an object, enter the following<br />

statements into the bottom text field so you can view the properties of the<br />

attribute node object returned by the method:<br />

document.getElementById(“output”).getAttributeNode(“COLS”)<br />

document.getElementById(“output”).getAttributeNode(“ROWS”)<br />

document.getElementById(“output”).getAttributeNode(“wrap”)<br />

document.getElementById(“output”).getAttributeNode(“style”)<br />

All (except the last) statements display a list of properties for each attribute<br />

node object. The last statement, however, returns nothing because the STYLE<br />

attribute is not specified for the element.<br />

getBoundingClientRect()<br />

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

Compatibility ✓ ✓<br />

Example<br />

Listing 15-27 employs both the getBoundingClientRect() and<br />

getClientRects() methods in a demonstration of how they differ. A set of elements<br />

is grouped within a SPAN element named main. The group consists of two<br />

paragraphs and an unordered list.<br />

elementObject.getBoundingClientRect()

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

Saved successfully!

Ooh no, something went wrong!