I intend to create a new Div element via javascript, but i am having problem appending my code to the DOM
<div id="container">
<div id="content">
</div
</div>
<script>
var container = document.getElementById('container');
function divCreate() {
var newDiv = document.createElement('div');
var newContent = document.createTextNode('Hello
this is a div is added via javasceipt);
newDiv.appendChild(newContent);
var currentDiv = document.getElementById('content');
document.body.container.insertBefore(newDiv,
currentDiv
}
divCreate();
</script>
my actual intention was to insert the new div before the content inside the
container. I do understand the DOM as a tree of objects and hierarchy too.I thought that i could navigate the tree via this hierarchy . that is from document--->body----->container.
It did worked on the container, but not the content div. Could someone please tell what I am missing here?
