Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>||Working with elements||</title>
- </head>
- <body>
- <div id='org_div1'> The text above has been created dynamically.</div>
- </body>
- <script>
- document.body.onload = addElement;
- var my_div = null;
- var newDiv = null;
- function addElement () {
- // create a new div element
- // and give it some content
- var newDiv = document.createElement("div");
- var newContent = document.createTextNode("Hi there and greetings!");
- newDiv.appendChild(newContent); //add the text node to the newly created div.
- // add the newly created element and its content into the DOM
- my_div = document.getElementById("org_div1");
- document.body.insertBefore(newDiv, my_div);
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment