Insert Elements Around Each Matching Elements .wrap()

.wrap(element)

element: {selector, html String, Element, jQuery Object | Function(index){...}}
e.g. $("span").wrap("<div>")

.wrap(element) will insert element around each elements in the matched set.

Example 1: $("b").wrap("<div>") will insert <div>...</div> around each <b>.
Before
<b>A</b>
<b>B</b>
After
<div>
  <b>A</b>
</div>

<div>
  <b>B</b>
</div>
Example 2: $("b").wrap( function(index){ return "<div> #: "+index+"</div>"}) will insert returned html string <div> #: index</div>, where index is <div> position in matched set, around each <b>.
Before
<b>A</b>
<b>B</b>
After
<div>
  #: 0
  <b>A</b>
</div>

<div>
  #: 1
  <b>B</b>
</div>
jQuery manipulation insertion .wrap()