Search code examples
jqueryhtmlprepend

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.


Solution

  • Use before():

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