86 Part III . Document Objects Reference Node (Web site translator)
86 Part III . Document Objects Reference Node methods Actions that modify the HTML content of a node in the W3C DOM world primar ily involve the methods defined for the prototype Node. Table 14-6 shows the meth ods and their support in the W3C DOM-capable browsers. Table 14-6 Node Object Methods (W3C DOM Level 2) Method Description IE5 NN6 appendChild(newChild) Adds child node to end Yes Yes of current node cloneNode(deep) Grabs a copy of the Yes Yes current node (optionally) with children hasChildNodes() Determines whether Yes Yes current node has children (Boolean) insertBefore(new, ref) Inserts new child in front Yes Yes of another child removeChild(old) Deletes one child Yes Yes replaceChild(new, old) Replaces an old child Yes Yes with a new one supports(feature, version) Determines whether the No Yes node supports a particular feature The important methods for modifying content are appendChild(), insertBefore(), removeChild(), and replaceChild(). Notice, however, that all of these methods assume that the point of view for the action is from the parent of the nodes being affected by the methods. For example, to delete an element (using removeChild()), you don t invoke that method on the element being removed, but rather on its parent element. This leaves open the possibility for creating a library of utility functions that obviate having to know too much about the precise containment hierarchy of an element. A simple function that lets a script appear to delete an element actually does so from its parent: function removeElement(elemID) { var elem = document.getElementById(elemID) elem.parentNode.removeChild(elem) } If this seems like a long way to go to accomplish the same result as setting the outerHTML property of an IE4+ object to empty, you are right. While some of this convolution makes sense for XML, unfortunately the W3C working group doesn t seem to have HTML scripters best interests in mind. All is not lost, however, as you see later in this chapter.
Check Tomcat Web Hosting services for best quality webspace to host your web application.