I want to append a div inside a div which have many divs inside itself. My code is shown below:
<div id="main">
<div class="random no"></div>
<div class="random no"></div>
<div class="random no"></div>
<div class="random no"></div>
<div class="mydiv"></div>
</div>
My jQuery code is:
$("#main").append("<div class='random no'> </div>");
But it appends after the last child of div “main”. How to insert that div before #mydiv?
DEMO
or
DEMO
or
DEMO
Related refs:
after()
.before()
.insertBefore()