Javascript: Adding an element to HTML Document

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);