Reputation: 553
I have a html structure like below:
<div class="element1>
</div>
I want to create another div.element right after div.element1 so I use element2.appendTo("div.element1")
but it's being created like below:
<div class="element1>
<div class="element2">
</div>
</div>
What I really what to be done is like below:
<div class="element1>
</div>
<div class="element2">
</div>
How this can be done?
Upvotes: 1
Views: 99
Reputation: 4572
You should use after to insert elements as you want.
Try it:
$('.element1').after(element2);
Upvotes: 2
Reputation: 11
With jQuery you can user after or insert to the parent:
$('#element1').after('#element2')
$('#element1').parent().append('#element2')
Upvotes: -1
Reputation: 1287
use insertAfter()
:-
$(".element2").insertAfter($(".element1"));
Upvotes: 0