You may also often encounter so summarized as follows:
Creation of 1,dom elements
Insertion of 2,dom elements
3,dom element substitution
Deletion of 4,dom elements
First, there are some simple DOM elements on the page
<div id= "Wrap" >
<div id= "a" >aaaaaaaa</div>
<div id= "B" >bbbbbbbb</div>
<div id= "C" >ccccccccc</div>
</div>
Next we create a DIV element, JS code:
var div_d = document.createelement (' div ');
div_d.innerhtml = "DDDDDDDD";
Div_d.id = "D";
There's no innertext here. To avoid browser compatibility cause some problems;
Then insert the DIV with ID D created in front of the DIV with DOM element ID b
var div_wrap = document.getElementById (' wrap ');
var div_b = document.getElementById (' B ');
Div_wrap.insertbefore (Div_d,div_b);
You can do this if you insert directly behind a child element with ID Wrap:
Div_wrap.insertbefore (Div_d,null);
If it is replaced Div_b is as follows:
Div_wrap.replacechild (Div_d,div_b);
Finally we delete the specified div with an element ID of b
Div_b.parentNode.removeChild (Div_b);
Or
Document.body.removeChild (Div_b);
Follow-up may have a number of derivative methods and applications this is not going to be written anymore.