Home

Javascript: Adding an element to HTML Document

Posted by SteveHardie | On: Nov 13 2009

Create and append a HTML element dynamically using javascript.

  var divTag = document.createElement("div");
  divTag.id = "divID";
  divTag.setAttribute("align","center");
  divTag.style.margin = "0px auto";                
  divTag.className ="dynamicDiv";                
  divTag.innerHTML = "This HTML Div tag created dynamically.";        
  document.body.appendChild(divTag);

Leave a comment