I'm having a little problem with hierarchy elements that are created dynamically.
Been trying to use insertBefore so they change place but no luck, wont get any errors but still I get the element under the other.
I have this function that creates a class called dice-window-wrapper and adds it to the page-content-wrapper.
var outerDiv = createElementWithClass('div', 'dice-window-wrapper'),
innerDiv = createElementWithClass('div', 'dice-menubar-wrapper');
outerDiv.appendChild(innerDiv);
document.getElementById("page-content-wrapper").appendChild(outerDiv);
And I get the print <div class="dice-window-wrapper">...</div>
No problem here.
Then I want to add an unordered list with some <li> tags, using this function:
icon_ul = createElementWithOutClass('ul');
var icon_ul = document.getElementById("page-menu-wrapper").appendChild(icon_ul);
icon_li = createElementWithId('li','icon-dice');
icon_ul.appendChild(icon_li);
document.getElementById("ul");
And the print will be <ul><li id="icon-dice"></li></ul>
The problem as I told is that <div class="dice-window-wrapper">...</div> should be under the string <ul><li id="icon-dice"></li></ul>.
But even if I change the icon_ul function from appendChild to insertBefore, nothing seems to change.
insertBeforecode look like? It expects two arguments: The new child and the element before the new element should be inserted: developer.mozilla.org/en-US/docs/DOM/Node.insertBefore.divintopage-content-wrapper, your second block adds anulintopage-menu-wrapper, so it seems your two blocks works "separately", yet you ask why the firstdivdoesn't have a certain relationship with the secondul?divis insidepage-content-wrapper, while yourulis insidepage-menu-wrapper, so you can't forceul"above" or "under"div, as their order is determined first by their parent.