Adding HTML Elements to a Page

Click the buttons to add elements to the page.

Code Example

  function doIt() {
    var newDiv = document.createElement("div");
    newDiv.innerHTML = "This is a DIV";
    newDiv.className = "class1";
    document.body.appendChild(newDiv);
		
    var btn = document.createElement("button");
    btn.innerHTML = "I'm a Button";
    document.body.appendChild(document.createElement('br'));
    document.body.appendChild(btn);
  }