312Part IIIDocument Objects (Best web hosting) ReferenceThis is another way to

312Part IIIDocument Objects ReferenceThis is another way to replace the text fragment following the myEMelement, but it is also rel- ative to the surrounding myPelement. If you now attempt to replace text after the end of themyPblock-level element, document.getElementById( myP ).replaceAdjacentText( afterEnd , Hooray! ) the text fragment is inserted after the end of the myPelement s tag set. The fragment is justkind of floating in the document object model as an unlabeled text node. Related Items:innerText, outerTextproperties; getAdjacentText(), insertAdjacentHTML(), insertAdjacentText()methods. replaceChild(newNodeObject, oldNodeObject) Returns:Nodeobject reference. Compatibility:WinIE5+, MacIE5+, NN6+, Moz1+, Safari1+ The replaceChild()method enables you to swap an existing child node object for a newnode object. Parameters for the replaceChild()method are node object references, andthey must be in the order of the new object followed by the object you want to replace. Theold object must be an immediate child node of the parent used to invoke the method, and thenew object must also be a legal child element within the document containment hierarchy. The method returns a reference to the child object that you replaced with the new object. This reference can be used as a parameter to any of the node-oriented insertion or replace- ment methods. Remember that replaceChild()is invoked from the point of view of a parent element. Ifyou simply want to change an element, you can do so more directly in WinIE5+ with theswapNode()or replaceNode()method. ExampleYou can see an example of replaceChild()as part of Listing 15-21 (for the appendChildproperty) earlier in this chapter. Related Items:appendChild(), removeChild(), replaceNode(), swapNode()methods. replaceNode( newNodeObject ) Returns:Nodeobject reference. Compatibility:WinIE5+, MacIE-, NN-, Moz-, Safari- The replaceNode()method is related to the replaceChild()method, but you invoke thismethod on the actual node you want to replace (instead of the object s parent). The soleparameter is a reference to a valid node object, which you can generate via the document. createElement()method or copy from an existing node. The value returned from themethod is a reference to the object that you replace. Thus, you can preserve a copy of thereplaced node by storing the results in a variable for use later. If the node you replace contains other nodes, the replaceNode()method removes all con- tained nodes of the original from the document. Therefore, if you want to change a wrappernode but want to maintain the original children, your script must capture the children andput them back into the new node as shown in the following example. ExampleListing 15-31 demonstrates three node-related methods: removeNode(), replaceNode(), andswapNode(). These methods work in WinIE5+ only. elementObject.replaceAdjacentText()