
Originally Posted by
TryingToLearn
If you also don’t mind, why is innerHTML on the container DIV hosing the bottom div? The way I understand innerHTML is that it sets HTML between the start and end tags of the object. I did not realize that this over wrote anything else added to the object.
innerHTML represents the entire content of an element, so if you specify that it should consist entirely of a text string, that's what you get.
I suppose you could have used
Code:
document.getElementById( "containerDiv" ).innerHTML = "Container text"+document.getElementById( "containerDiv" ).innerHTML
but thereafter the inner div would not be addressable. A better way would be to prepend the current content using insertBefore
Code:
function buildDIVs()
{
addPageMarkup();
var cd=document.getElementById( "containerDiv" );
cd.insertBefore(document.createTextNode("Container text"), cd.firstChild);
document.getElementById( "innerDiv" ).innerHTML = "Inner Div text";
}
Bookmarks