Skip to content

Instantly share code, notes, and snippets.

@nikkaroraa
Created November 13, 2017 20:07
Show Gist options
  • Save nikkaroraa/6d527442adc4342a29e964d5914d1936 to your computer and use it in GitHub Desktop.
Save nikkaroraa/6d527442adc4342a29e964d5914d1936 to your computer and use it in GitHub Desktop.
Adding to DOM - 2
<!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