wrap--添加及去除外层dom的方法
Wrap an HTML structure around each element in the set of matched elements. .wrap()
Wrap an HTML structure around all elements in the set of matched elements. .wrapAll()
Wrap an HTML structure around the content of each element in the set of matched elements. .wrapInner()
Remove the parents of the set of matched elements from the DOM, leaving the matched elements in their place. .unwrap()
<div class="container"> <div class="inner">Hello</div> <div class="inner">Goodbye</div> </div> $('.inner').wrap('<div class="new" />'); <div class="container"> <div class="new"> <div class="inner">Hello</div> </div> <div class="new"> <div class="inner">Goodbye</div> </div> </div> <div class="container"> <div class="inner">Hello</div> <div class="inner">Goodbye</div> </div> $('.inner').wrapAll('<div class="new" />'); <div class="container"> <div class="new"> <div class="inner">Hello</div> <div class="inner">Goodbye</div> </div> </div> <div class="container"> <div class="inner">Hello</div> <div class="inner">Goodbye</div> </div> $('.inner').wrapInner('<div class="new" />'); <div class="container"> <div class="inner"> <div class="new">Hello</div> </div> <div class="inner"> <div class="new">Goodbye</div> </div> </div>