作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个 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...
最佳答案
您正在寻找 :nth-child
: http://api.jquery.com/nth-child-selector/
它的工作原理如下:
$('.control div:nth-child(2), .control div:nth-child(3), .control div:nth-child(4)').remove();
请注意,:nth-child
使用基于一个的索引,因此第一个元素的索引为 1。
更新:为了回答这个问题,OP 在评论中发布了
If i dont know how many divs will occur after the input field is there any way to CUT or SLICE all the divs or any elements that occur after the second child of the Control DIV...
答案是肯定的,为此您需要 :gt:
选择器:http://api.jquery.com/gt-selector/
$('.control div:gt(1)').remove()
与 :nth-child
不同,:gt
使用从零开始索引,因此第一个元素的索引为 0。
关于jquery - 在一定数量后删除 DIV 的子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9511770/
我正在尝试开发右边框/Angular 具有特定 Angular (30°) 的表格。我见过一些类似的解决方案,但它们都无法在一定程度上发挥作用。如果我想从 30° 改变到 20°,我不想花太多力气。
我是一名优秀的程序员,十分优秀!