Javascript examples for DOM HTML Element:Div
You can create a <div> element by using the document.createElement() method:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">create a DIV element</button> <script> function myFunction() {/* ww w. jav a 2s.c o m*/ var x = document.createElement("DIV"); var t = document.createTextNode("This is a div element."); x.setAttribute("style", "background-color: red;"); x.appendChild(t); document.body.appendChild(x); } </script> </body> </html>