[英]How to create a child div that would wrap around all other child divs
I have this html structure: 我有这个HTML结构:
<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"? 我怎么能使用jquery将div div添加到div“a”中,它将包围“b”,“c”和“d”? Basically, the final html I want should look like this: 基本上,我想要的最终html应如下所示:
<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()
使用.wrapInner()
$('.a').wrapInner('<div class="test"></div>')
or 要么
use .wrapAll()
: 使用.wrapAll()
:
$('.a div').wrapAll('<div class="child"></div>')
$('.a').html('<div class="child">'+$('.a').html()+'</div>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.