Create a new HTML elements (nodes)


<body>
  <div ID = "DIV1">     <P ID = "P1"> This is a paragraph. </ P>     <P ID = "P2"> This is another paragraph. </ P>   </ div>
</ body> <Script>
  var = document.getElementById Element ( "DIV1");
. 1, creates a new <p> element   var para = document.createElement ( "p" );
2, create a text node, because like the <p> tag put text   var node = document.createTextNode ( "this is new text.");
3, the <p> elements add text node   para.appendChild (node); 4, adding new elements to an existing div element <p>   element. (para); . 5, a case will be more than the div element p </ script> appendChild

Guess you like

Origin www.cnblogs.com/shun1015/p/11409500.html