wrap() method in jQuery

wrap() in jQuery

This method is used to wrap an HTML structure around each element in the set of matched elements.

Syntax 1

$(selector).wrap(wrappingElement)

  • wrappingElement - It can include selector, element, HTML string, or jQuery object to be to wrapped around the matched elements.
Syntax 2

$(selector).wrap(function(index))

  • index - index position of the element in the set.

Example 1

Try Yourself

Example 2 - with function

Try Yourself