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.

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

removeAttributeNode(attributeNode)<br />

setAttributeNode(attributeNode)<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 />

setAttributeNode() and removeAttributeNode() methods for the P element in<br />

the page. The task is to create and add a STYLE attribute to the P element. Begin by<br />

creating a new attribute and storing it temporarily in the global variable a:<br />

a = document.createAttribute(“style”)<br />

Assign a value to the attribute object:<br />

a.nodeValue = “color:red”<br />

Now insert the new attribute into the P element:<br />

document.getElementById(“myP”).setAttributeNode(a)<br />

The paragraph changes color in response to the newly added attribute.<br />

Due to the NN6 bug that won’t allow the method to return a reference to the<br />

newly inserted attribute node, you can artificially obtain such a reference:<br />

b = document.getElementById(“myP”).getAttributeNode(“style”)<br />

Finally, use the reference to the newly added attribute to remove it from the<br />

element:<br />

document.getElementById(“myP”).removeAttribute(b)<br />

Upon removing the attribute, the paragraph resumes its initial color. See the<br />

example for the setAttribute() method later in this chapter to discover how you<br />

can perform this same kind of operation with setAttribute().<br />

removeBehavior(ID)<br />

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

Compatibility ✓ ✓<br />

Example<br />

See Listings 15-19a and 15-19b earlier in this chapter for examples of how to use<br />

addBehavior() and removeBehavior().<br />

elementObject.removeBehavior()

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

Saved successfully!

Ooh no, something went wrong!