Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to add elements in javascript html

  //adding 'p' tag to body

  var tag = document.createElement("p"); // <p></p>
  var text = document.createTextNode("TEST TEXT"); 
  tag.appendChild(text); // <p>TEST TEXT</p>
  var element = document.getElementsByTagName("body")[0];
  element.appendChild(tag); // <body> <p>TEST TEXT</p> </body>
Source by www.tutorialspoint.com #
 
PREVIOUS NEXT
Tagged: #add #elements #javascript #html
ADD COMMENT
Topic
Name
3+6 =