Reputation: 8814
I have the following part of DOM:
<div id="content">
<div id="div-1"></div>
<!-- here new DOM -->
<div id="div-2"></div>
</div>
I need to insert new part of DOM between "div-1" and "div-2".
How I can do it with jQuery?
Upvotes: 2
Views: 497
Reputation: 1660
$('#div-1').after('<div>new content</div>')'
or
$('<div>new content</div>').insertAfter($('#div-1'));
Upvotes: 1
Reputation: 65254
use .after()
on div-1
$('#div-1').after('<div id="new">new div</div>');
or use .before()
on div-2
$('#div-2').before('<div id="new">new div</div>');
Upvotes: 4