dom add and delete nodes

// find DIV1 
var DIV1 = document.getElementById ( " DIV1 " );
 // create a label p 
var p = document.createElement ( ' p ' );
 // Create a text node 
var p1txt = document.createTextNode ( ' P1 ' ); 
p.appendChild (p1txt);
 // add nodes 
div1.appendChild (P);
 // delete the node Div2 
var Div2 = document.getElementById ( ' Div2 ' );
 // their own to kill 
div2.parentNode.removeChild (div2 );

 

Guess you like

Origin www.cnblogs.com/angdh/p/11043245.html