Insert Elements Around Each Matching Element Inner Content .wrapInner()

.wrapInner(element)

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

.wrapInner(element) will insert element around the inner content of each element in the matched set.

Example 1: $("div").wrapInner("<span>") will insert <span>...</span> around the content of each <div>.
Before
<div>
 <b>A</b>
</div>

<div>
  <b>B</b>
</div>
After
<div>
  <span>
    <b>A</b>
  </span>
</div>

<div>
  <span>
    <b>B</b>
  </span>
</div>
Example 2: $("div").wrapInner( function(index) { return "<span>"+index+"" ;} ) will insert <span>index...</span> around the content of each <div>, where index is <div> position in the matched set.
Before
<div>
 <b>A</b>
</div>

<div>
  <b>B</b>
</div>
After
<div>
  <span>
    0
    <b>A</b>
  </span>
</div>

<div>
  <span>
    1
    <b>B</b>
  </span>
</div>
jQuery manipulation insertion .wrapInner()