Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
Jquery 删除特定数字后DIV的子项_Jquery_Jquery Ui - Fatal编程技术网

Jquery 删除特定数字后DIV的子项

Jquery 删除特定数字后DIV的子项,jquery,jquery-ui,Jquery,Jquery Ui,我有这个HTML <div class="control"> <label class="">Label Here</label> <input type="text"> <div class="ui-resizable"></div> <div class="ui-resizable-handle"></div> <div class="ui-

我有这个HTML

<div class="control">
     <label class="">Label Here</label>
     <input type="text">
     <div class="ui-resizable"></div>
     <div class="ui-resizable-handle"></div>
     <div class="ui-resizable-handle ui-resizable-se"></div>
     <div style="display: inline;" class="delete"><span class="ui-icon ui-icon-closethick">close</span> </div>
     <div style="display: inline;" class="properties txtbox"><span class="ui-icon ui-icon-wrench">Properties</span></div>
</div>

在这里贴标签
接近
性质
如何使用jQuery从这个HTML中删除第二个、第三个和第四个div

$('.controll>div:gt(1)').remove();
:gt
选择器将允许您选择索引大于1的,即索引为3的。元素和更多

下面是一个示例:

您可以这样做

$('.control div:nth-child(2)').remove();
$('.control div:nth-child(3)').remove();
$('.control div:nth-child(4)').remove();
或者你也可以这样做

$('.control div:nth-child(1)').siblings().remove();

您正在查找第n个孩子:

它的工作原理如下:

$('.control div:nth-child(2), .control div:nth-child(3), .control div:nth-child(4)').remove();
请注意,
:n子元素
使用基于一的索引,因此第一个元素具有索引1

更新:为了回答这个问题,OP发表了评论


如果我不知道输入字段存在后会出现多少个div 是否可以剪切或切片所有div或之后出现的任何元素 控制部分的第二个子项

答案是肯定的,为此您需要
:gt:
选择器:


与第n个子元素不同,
:gt
使用基于零的索引,因此第一个元素的索引为0。

如果您指的是那些特定的元素:

$(".ui-resizable-handle, .delete").remove();
如果您指的是位置2-4处的div,则无论标记如何,第n-child()个答案中的一个都会起作用。

尝试:


$('.control').find("div").slice(1, 4).remove();

如果我不知道输入字段之后会出现多少个DIV,是否有任何方法可以剪切或切片所有DIV或控制DIV的第二个子项之后出现的任何元素……是的,您使用
:gt
选择器。有关解释,请参阅我答案中的更新。您的第一个解决方案不起作用。在第一次删除后,少了一个元素,因此索引都会更改。这非常有效,另一个示例代码$('.pos_abs.mjx box>span:gt(150)')。remove();

$('.control').find("div").slice(1, 4).remove();