0

提琴手

我正在尝试从每个节点中删除默认值。我尝试了以下代码

$( document ).ready(function() {
$( "table tbody tr td:nth-of-type(1) select option").first().remove();
});

它从第一个节点中删除了元素。有人可以帮我从每个节点中删除第一个元素。

4

2 回答 2

2
$("table tbody tr td:nth-of-type(1) select option:first-child").remove();

Demo: http://jsfiddle.net/rqtaz/6/

于 2013-10-15T21:18:17.380 回答
1

.first() returns the first element in the set.

You want to use the :first-child selector, which will filter the simple selector you apply it to to only match the first child of the parent:

$("table tbody tr td:first-child select option:first-child")

This will only match <option> elements that are the first child of their respective parents.

You can also use it on the td.

于 2013-10-15T21:18:28.873 回答