prependTo() method in jQuery

prependTo() in jQuery

This method is used to insert every element in the set of matched elements at the beginning of the target.

Syntax 1

$(selector).prependTo(targetSelector)

  • targetSelector - A selector, element, array of elements, HTML string, or jQuery object; the matched set of elements will be inserted before the element specified in this parameter.
Syntax 2

$(content).prependTo(targetSelector)

  • targetSelector - A selector, element, array of elements, HTML string, or jQuery object; the matched set of elements will be inserted before the element specified in this parameter.
  • content - html string or text

Example 1

Try Yourself

Example 2

Try Yourself