.wrap() | jquery out html
Description:WrapanHTMLstructurearoundeachelementinthesetofmatchedelements.The.wrap()functioncantakeanystringorobjectthatcouldbepassedtothe$()factoryfunctiontospecifyaDOMstructure.Thisstructuremaybenestedseverallevelsdeep,butshouldcontainonlyoneinmostelement.Acopyofthisstructurewillbewrappedaroundeachoftheelementsinthesetofmatchedelements.Thismethodreturnstheoriginalsetofelementsforchainingpurposes.ConsiderthefollowingHTML:1234
Description: Wrap an HTML structure around each element in the set of matched elements.
The .wrap() function can take any string or object that could be passed to the $() factory function to specify a DOM structure. This structure may be nested several levels deep, but should contain only one inmost element. A copy of this structure will be wrapped around each of the elements in the set of matched elements. This method returns the original set of elements for chaining purposes.
Consider the following HTML:
1
2
3
4
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
Using .wrap(), we can insert an HTML structure around the inner <div> elements like so:
1
$( ".inner" ).wrap( "<div class=new></div>" );
...