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.

Chapter 1 ✦ Generic HTML Element Objects (Chapter 15)<br />

setAttribute(“attributeName”, value<br />

[, caseSensitivity])<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 experiment with the<br />

setAttribute() method for the elements in the page. For IE4, use the document.<br />

all notation; IE5 and NN6 understand the W3C standard getElementById()<br />

method of addressing an element.<br />

Setting attributes can have immediate impact on the layout of the page (just as<br />

setting an object’s properties can). Enter these sample statements into the top text<br />

box to view attribute values:<br />

IE4+:<br />

document.all.myTable.setAttribute(“width”, “80%”)<br />

document.all.myTable.setAttribute(“border”, “5”)<br />

IE5+/NN6:<br />

document.getElementById(“myTable”).setAttribute(“width”, “80%”)<br />

document.getElementById(“myTable”).setAttribute(“border”, “5”)<br />

setAttributeNode()<br />

See removeAttributeNode().<br />

setCapture(containerBoolean)<br />

See releaseCapture().<br />

setExpression(“propertyName”,<br />

“expression”,”language”)<br />

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

Compatibility ✓ ✓<br />

Example<br />

Listing 15-32 shows the setExpression(), recalc(), and getExpression()<br />

methods at work in a DHTML-based clock. Figure 1-3 shows the clock. As time clicks<br />

91<br />

elementObject.setExpression()

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

Saved successfully!

Ooh no, something went wrong!