我正在尝试查找并非表元素的后代的所有表元素。例如,我想在**之间选择所有这些
<div>
<**table**>
<tr>...</tr>
<tr>...</tr>
<tr>
<table>
....
</table>
</tr>
</**table**>
<div>
<**table**>
...
</**table**>
</div>
</div>本质上,我希望找到所有顶级表,而不是它们的后代表。DOM的结构没有得到保证,所以我不能只使用$("div > table")
发布于 2015-01-27 23:56:54
一个简单的解决方案是选择所有表并筛选出那些具有表祖先的表:
var $tables = $("table")
.filter(function() { return $(this).parents("table").length == 0; });发布于 2015-01-28 00:01:34
您可以选择没有子表元素的所有表
$("table:not(:has(table))")发布于 2015-01-27 23:55:44
好的,请考虑以下几点:
$("table").addClass("test"); // add new class to all the tables <br/><br/>
$("tr").children().removeClass("test"); // remove this class for all the children of tr<br/><br/>
$("td").children().removeClass("test"); // remove this class for all the children of td<br/><br/>
$(".test") //now select the upper most table with its classhttps://stackoverflow.com/questions/28182235
复制相似问题