23.04.2013 Views

javascript

javascript

javascript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Figure 7–14. Custom members are not attributes.<br />

CHAPTER 7 ■ TRAVERSING AND MODIFYING THE DOM TREE<br />

■ Note If you are wondering whether an attribute is distinct from the member it maps to, it is. An attribute is<br />

represented by an Attr node, but its corresponding member is not.<br />

Querying Attr Nodes<br />

DOM provides a way to represent both HTML and XML markup. Whereas HTML attribute values may be<br />

fully represented with strings, this is not so for XML attributes. For this reason, DOM provides an Attr<br />

interface for representing attributes as nodes. Those are not part of the DOM tree. So, you will not bump<br />

into them while traversing the DOM.<br />

Anyway, for HTML markup, Attr nodes have a single Text node child that you may query by way of<br />

the value member. On the other hand, XML Attr nodes may contain both a Text and EntityReference<br />

node, which is why XML attributes cannot be conveyed with just a string.<br />

Click Clear in both Firebug panels, and let’s try querying the members of the Attr node representing<br />

the class attribute for the Twitter . First save the Attr node in a variable named myAttrNode. Note<br />

that you can query the Attr node with Element.getAttributeNode(). So, append Node to<br />

Element.getAttribute(), and you’re good to go:<br />

var myAttrNode = document.getElementById("twitter").getAttributeNode("class");<br />

285

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

Saved successfully!

Ooh no, something went wrong!