I. Creating a Node
This piece of code creates a new <p> element
var dom = document.craeteelement ("P");
If you want <p> add text, you must create a node for the text
var node = document.createTextNode ("This is new Textnode");
Then you have to add this node to the <p> element
Dom.appendchild (node);
This time has been created successfully.
Two. Delete a node
For example, there is an HTML code
<div id= "Div1" ><p id= "P1" > This is a paragraph. </p><p id= "P2" > this is another paragraph. </p></div>
Script
<script>var Parent=document.getelementbyid ("Div1"); var Child=document.getelementbyid ("P1"); Parent.removechild (Child);</script>
JS Delete node When you need to find its parent node, if you can delete a node without referencing the parent element, it is very good, but unfortunately, the DOM needs to clear the element you want to delete, Yi and its parent element
This is a common practice:
var Child=document.getelementbyid ("P1"); Child.parentNode.removeChild (child);
JavaScript manipulating DOM objects