Reputation: 1055
Trivial question, but couldn't figure it out. Googled it a bit, but surprisingly didn't find a clear answer for my particular example.
I have got an html bit:
<div id="main">
<div id="box15"></div>
<div id="box12"></div>
<div id="box7"></div>
<div id="box1"></div>
<div id="box3"></div>
</div>
How would I append html bit <div id="box19"></div>
to main
id after specific child, for example after <div id="box12"></div>
?
Upvotes: 0
Views: 53
Reputation: 133403
You can use .insertAfter()
Insert every element in the set of matched elements after the target.
Code
$('<div id="box19">box19</div>').insertAfter("#box12");
OR
You can use .after()
Insert content, specified by the parameter, after each element in the set of matched elements.
Code
$("#box12").after('<div id="box19">box19</div>' );
Upvotes: 2
Reputation: 862
var div = document.getElementById('main');
div.innerHTML = div.innerHTML + '';
Upvotes: 0
Reputation: 17366
You can Use insertAfter()
$('<div id="box19"></div>').insertAfter("div#box12")
Upvotes: 1