DOM Node Deletion function removeChild () usage instance, domremovechild
This example describes how to use the removeChild () function to delete a DOM node. Share it with you for your reference. The specific analysis is as follows:
To delete a node, DOM must be deleted at the height of the parent node. The Code is as follows:
Copy codeThe Code is as follows: <Head>
<Script type = "text/javascript">
Function t (){
// Train of thought: 1. First find the node to be deleted; 2. Find its parent node and delete the child node from the parent node perspective.
Var nodeul = document. getElementsByTagName ('ul ') [0]; // locate the parent node
Var li_lan = nodeul. children [2]; // locate the subnode to be deleted
Nodeul. removeChild (li_lan); // use the removeChild () function to delete
}
</Script>
</Head>
<Body>
<Div id = "container">
<Ul>
<Li> spring </li>
<Li> summer </li>
<Li> blue sky </li>
<Li> autumn </li>
<Li> Winter </li>
</Ul>
</Div>
<Div id = "copyul">
</Div>
<Hr/>
<Button onclick = "t ()" value = ""> delete a subnode </button>
</Body>
</Html>
I hope this article will help you design javascript programs.