AppendChild after ID

This is a discussion on "AppendChild after ID" within the JavaScript Forum section. This forum, and the thread "AppendChild after ID are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Apr 6th, 2007, 09:45
Junior Member
Join Date: Feb 2006
Location: England
Age: 20
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Echilon Send a message via MSN to Echilon
AppendChild after ID

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>
Reply With Quote

  #2 (permalink)  
Old Apr 6th, 2007, 19:23
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: AppendChild after ID

There's the long way (which is ugly and takes a lot to learn) and there's the jQuery way:

Step 1: Get jQuery

Step 2: Use the after method to insert HTML after an element.
Code: Select all
<script type="text/javascript">
function DoInsert(){
 $('#container #child1').after('<div id="child1a">Woohoo!!! I'm child1a</div>');
}
</script>
Call function DoInsert() to insert the new div.
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
Reply

Tags
element, javascript

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 00:02.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43