Add examples of JavaScript DOM nodes

  • 2020-03-30 03:31:20
  • OfStack

<!DOCTYPE html> 
<html> 
<body> 

<div id="div1"> 
<p id="p1"> This is a paragraph. </p> 
<p id="p2"> This is another paragraph. </p> 
</div> 

<script> 
var para=document.createElement("h1"); 
var node=document.createTextNode(" This is a new paragraph. "); 
para.appendChild(node); 
//Put the STR in the node in the h1 paragraph
//Make it <H1> This is a new passage </ h1>

var element=document.getElementById("div1"); 
element.appendChild(para); 

//Put para in a div

</script> 

</body> 
</html>

Related articles: