insertBefore() method in jQuery

insertBefore in jQuery

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

Syntax 1

$(selector).insertBefore(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.
Syntax 2

$(content).insertBefore(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.
  • content - html string or text

Example 1

Try Yourself

Example 2

Try Yourself