Reputation: 3302
I am trying to add a div like below
<div id="topheader" class="topheader">
<ul>
<li>
<a href="#" title="Library">Library</a>
</li>
<li>
<a href="#" title="My Uni">My Uni</a>
</li>
<li>
<a href="#" title="Staff Intranet">Staff Intranet</a>
</li>
</ul>
</div>
in between two other divs
<div id="w3">
.... new div to be here ...
<div id="head">
I need to get this done using javascript or motools and not jquery.
Upvotes: 1
Views: 371
Reputation: 3729
var div_before = document.getElementById("w3");
var new_div = document.getElementById("topheader");
div_before.parentNode.insertBefore(new_div, div_before.nextSibling);
Upvotes: 2
Reputation: 1497
You can do it using inject
var headEle = document.id('head');
new Element('div', {
"class": 'topheader',
"id": 'topheader',
html: '<ul><li><a href="#" title="Library">Library</a></li><li><a href="#" title="My Uni">My Uni</a></li><li><a href="#" title="Staff Intranet">Staff Intranet</a></li></ul>'
}).inject(headEle, 'before');
Here is a working JS FIDDLE
Upvotes: 2