Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append Child After ID

Status
Not open for further replies.

Echilon

Programmer
Feb 22, 2007
54
GB
I have a div containing a few elements. Is it possible to append a child after an element with a certain ID?
Eg:
<div id="container>
<div id="child1"></div>
<div id="child2"></div>
</div>

Could I append a child after child1, to give:
<div id="container>
<div id="child1"></div>
<div id="child1a"></div>
<div id="child2"></div>
</div>
 
Hi

Echilon said:
Is it possible to append a child after an element with a certain ID?
Yes, but not directly.
DOM:element.insertBefore said:
There is no [tt]insertAfter[/tt] method, however it can be emulated using a combination of [tt]insertBefore[/tt] and [tt]nextSibling[/tt].
Code:
d1a=document.createElement('div')
d1=document.getElementById('child1')
d1.parentNode.insertBefore(d1a,d1.nextSibling)

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top