Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  29] [ 7]  / answers: 1 / hits: 17256  / 14 Years ago, wed, may 5, 2010, 12:00:00

How do I append a element a specific index of the children elements using jQuery append e.g. if I have:



<div class=.container>
<div class=item><div>
<div class=item><div>
<div class=item><div>
<div class=item><div>
</div>


and I want to append another item between the second and third item?


More From » jquery

 Answers
43

There are a few options:



$(div.container div.item).eq(2).after($('your html'));

$(div.container div.item:nth-child(3)).after($('your html'));

$($(div.container div.item)[2]).after($('your html'));


The same options, but inserting into the same position using before:



$(div.container div.item).eq(3).before($('your html'));

$(div.container div.item:nth-child(4)).before($('your html'));

$($(div.container div.item)[3]).before($('your html'));

[#96867] Monday, May 3, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yosefleod

Total Points: 113
Total Questions: 100
Total Answers: 115

Location: Egypt
Member since Tue, May 3, 2022
2 Years ago
;