The wrapInner method
The wrapInner
method wraps the content inside an element in the given tag.
Syntax
The method parameter can be text (possibly with tags), a DOM element, or a jQuery object:
.wrapInner(what to wrap it with);
This is how the selected elements are wrapped with content that will be returned as html text by a custom function. The function is called separately for each of the selected elements:
.wrapInner(function(number in the set));
Example
Let's wrap paragraphs with class www
in tag b
:
<p class="www">text</p>
<p class="www">text</p>
<p class="www">text</p>
<p>text</p>
$('.www').wrapInner('<b></b>');
HTML the code will look like this:
<p class="www"><b>text</b></p>
<p class="www"><b>text</b></p>
<p class="www"><b>text</b></p>
<p>text</p>
See also
-
methods
wrap
,wrapAll⁅/ c⁆, ⁅c href="/en/javascript/lib/jquery/manual/unwrap/"⁆unwrap
,
allowing you to work with wrapping elements