Created
November 13, 2017 20:07
-
-
Save nikkaroraa/6d527442adc4342a29e964d5914d1936 to your computer and use it in GitHub Desktop.
Adding to DOM - 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>DOM Manipulation</title> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| </div> | |
| </body> | |
| <script> | |
| //creating a new element node | |
| var newElementNode = document.createElement('p'); | |
| //creating a new text node | |
| var newTextNode = document.createTextNode('New Content'); | |
| //appending the new text node to the new element node | |
| newElementNode.appendChild(newTextNode); | |
| //appending the new element node to existing div | |
| var div = document.querySelector('.container'); | |
| div.appendChild(newElementNode); | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment