Harsha M V Harsha M V - 6 months ago 28
Javascript Question

jQuery Prepend before an element

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

Use before():

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