Copy codeThe Code is as follows: <title> </title>
<Script type = "text/javascript">
Function createNode (){
Var pNode = document. createElement ('P ');
Var tNode = document. createTextNode ('fireworks under yangju on October 11 ');
PNode. appendChild (tNode );
Document. body. appendChild (pNode );
}
Function r (){
Var pNode = document. createElement ('P ');
Var tNode = document. createTextNode ');
PNode. appendChild (tNode );
// Obtain the node to be replaced
Var reNode = document. getElementsByTagName ('P') [0];
// This method is only applicable to IE browsers.
// ReNode. replaceNode (pNode, reNode );
// Applicable to various browsers
ReNode. parentNode. replaceChild (pNode, reNode );
}
Function reNode (){
Var oldNode = document. getElementsByTagName ('P') [0];
// OldNode. parentNode returns the parent node of the p node, which is the body
// Use the removeChild method of the body node to delete the oldNode
OldNode. parentNode. removeChild (oldNode );
}
</Script>
</Head>
<Body>
<Input id = "Button1" type = "button" value = "create node" onclick = "createNode ()"/>
<Input id = "Button2" type = "button" value = "replace node" onclick = "r ()"/>
<Input id = "Button3" type = "button" value = "delete node" onclick = "reNode ()"/>
</Body>
</Html>