I have this html structure:
<div class="a">
<div class="b"></div>
<div class="c"></div>
<div class="d"></div>
</div>
How can would I use jquery to add child div to div "a" that would wrap around "b", "c" and "d"? Basically, the final html I want should look like this:
<div class="a">
<div class="child">
<div class="b"></div>
<div class="c"></div>
<div class="d"></div>
</div>
</div>
Thanks
Try this:
$(function() {
$('.a > div').wrapAll('<div class="child"></div>');
});
use .wrapInner()
$('.a').wrapInner('<div class="test"></div>')
or
use .wrapAll()
:
$('.a div').wrapAll('<div class="child"></div>')
$('.a').html('<div class="child">'+$('.a').html()+'</div>');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.