jQuery Prepend before an element

Harsha M V picture Harsha M V · Nov 17, 2010 · Viewed 14.6k times · Source

I have a html structure like this/

<li id="1"></li>
<li id="2"></li>
<li id="3"></li>
<li id="comment-box"></li>

now i wanna prepend

<li id="4"></li>

before comment-box.

i am submitting a form from the comment box and once its a success i wanna do the prepend.

Answer

Dr.Molle picture Dr.Molle · Nov 17, 2010

Use before():

$('#comment-box').before('<li id="4"></li>')