jQuery Prepend Prepending an element to a container


Example

Solution 1:

 $('#parent').prepend($('#child')); 

Solution 2:

 $('#child').prependTo($('#parent'));

Both solutions are prepending the element #child (adding at the beginning) to the element #parent.

Before:

<div id="parent">
  <span>other content</span>
</div>
<div id="child">

</div>

After:

<div id="parent">
  <div id="child">

  </div>
  <span>other content</span>
</div>