Web hosting domain names - 237Chapter 15Generic HTML Element ObjectsnextSiblingpreviousSiblingValue:Object reference.Read-Only Compatibility:WinIE5+, MacIE5+,

237Chapter 15Generic HTML Element ObjectsnextSiblingpreviousSiblingValue:Object reference.Read-Only Compatibility:WinIE5+, MacIE5+, NN6+, Moz1+, Safari1+ A sibling nodeis one that is at the same nested level as another node in the hierarchy of anHTML document. For example, the following pelement has two child nodes (the emand spanelements). Those two child nodes are siblings of each other.

MegaCorp is the source of the hottest gizmos.

Sibling order is determined solely by the source code order of the nodes. Therefore, in theprevious example, the emnode has no previousSiblingproperty. Meanwhile, the spannodehas no nextSiblingproperty (meaning that these properties return null). These propertiesprovide another way to iterate through all nodes at the same level. ExampleThe following function assigns the same class name to all child nodes of an element: function setAllChildClasses(parentElem, className) { var childElem = parentElem.firstChild; while (childElem.nextSibling) { childElem.className = className; childElem = childElem.nextSibling; } } This example is certainly not the only way to achieve the same results. Using a forloop toiterate through the childNodescollection of the parent element is an equally valid approach. Related Items:firstChild, lastChild, childNodesproperties; hasChildNodes(), insertAdjacentElement()methods. nodeNameValue:String.Read-Only Compatibility:WinIE5+, MacIE5+, NN6+, Moz1+, Safari1+ For HTML and XML elements, the name of a node is the same as the tag name. The nodeNameproperty is provided for the sake of consistency with the node architecture specified by theformal W3C DOM standard. The value, just like the tagNameproperty, is an all-uppercasestring of the tag name (even if the HTML source code is written with lowercase tags). Some nodes, such as the text content of an element, do not have a tag. The nodeNameprop- erty for such a node is a special value: #text. Another kind of node is an attribute of an ele- ment. For an attribute, the nodeNameis the name of the attribute. See Chapter 14 for moreabout Nodeobject properties. ExampleThe following function demonstrates one (not very efficient) way to assign a new class nameto every pelement in an IE5+ document: function setAllPClasses(className) { for (var i = 0; i < document.all.length; i++) { if (document.all[i].nodeName == P ) { document.all[i].className = className; elementObject.nodeName