Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery:只包装第一个和第二个子级,不包装其余的子级_Javascript_Jquery_Children_Wrapall - Fatal编程技术网

Javascript jQuery:只包装第一个和第二个子级,不包装其余的子级

Javascript jQuery:只包装第一个和第二个子级,不包装其余的子级,javascript,jquery,children,wrapall,Javascript,Jquery,Children,Wrapall,在我的实际代码中: 从HTML ID中删除 $("#mother div:eq(0), #mother div:eq(1)").wrapAll("<div id='father'></div>") $(“#母div:eq(0),#母div:eq(1)”).wrapAll(“”) 夏普不应成为id的一部分。然后你可以做: $('#child-01, #child-02').wrapAll('<div id="#mywrap" />'); $('child

在我的实际代码中:


从HTML ID中删除

$("#mother div:eq(0), #mother div:eq(1)").wrapAll("<div id='father'></div>")
$(“#母div:eq(0),#母div:eq(1)”).wrapAll(“”)

夏普不应成为id的一部分。然后你可以做:

$('#child-01, #child-02').wrapAll('<div id="#mywrap" />');
$('child-01,'child-02').wrapAll('');
如前所述,首先从id属性中删除
#
前缀。此外,还要匹配您的结束标记,当前您有一个
,其中应该有一个

然后,您可以使用和这样做:

$("#mother div:lt(2)").wrapAll("<div id='myWrap'></div>");
$(“#母分区:lt(2)”).wrapAll(“”);
这将获取索引2以下的所有内容(0和1是前2个),然后将其包装

$(文档).ready(函数(){
$(“.new-grid_uuu项:第n个子项(1),.new-grid_uuu项:第n个子项(2)”).wrapAll(“”);
});

请格式化您的代码,并添加一些文本,说明为什么这会回答问题
$(document).ready(function(){
  $(".new-grid__item:nth-child(1), .new-grid__item:nth-child(2)").wrapAll('<div class="child"></div>');
});