Reputation: 34188
suppose i have div like
<div id='main'>
<div id='child'>my static content</div>
</div>
$('#main').append("<div class='mycontent'>I'm new box by append</div>");
or
$('#main').appendTo("<div class='mycontent'>I'm new box by append</div>");
i know i can use append() and appendTo method to insert anything into main div. but i need to know that how can i insert content into main div before child div. content will be pushed into main div before child div. please help me with concept.
thanks
Upvotes: 1
Views: 4622
Reputation: 3539
try this:
$('#child').before("<div class='mycontent'>I'm new box by append</div>");
also maybe will be useful:
$('#child').after("<div class='mycontent'>I'm new box by append</div>");
Upvotes: 0
Reputation: 19237
if you want it before the last child div:
$("#main > div:last-child").before("<div class='mycontent'>I'm new box by append</div>");
or if you want it before a specific div:
$("#child").before("<div class='mycontent'>I'm new box by append</div>");
Upvotes: 2