jQuery初学者::仅适用于直接后代 [英] JQuery beginner: :has for direct descendants only
问题描述
假设树形结构如下: (糟糕的旧版布局,很抱歉)
Assuming a tree structure like the following: (Ugly legacy layout, sorry)
<tr> (1) dont want to select this one
<td>
<table>
<tr> (2) not a "special" td, dont select
<td.normal>
<tr> (3) this is what I want to select
<td.special>
<tr>
<td.normal>
我想选择具有特殊类的td的tr作为直接后代, 即,只有(2),不是(3)[其td不特殊],也不是(1)[特殊的td不是直接后代,而是孙子"]
I want to select the tr which has a td with class special as direct descendant, i.e. only (2), not (3) [its td is not special], and also not (1) [special td is not a direct descendant but a "grandkid"]
我尝试了
$("tr:has(td.special)");
但是这给了我(1)和(2),因为:has的意思是在我所有后代之中".
but that gives me (1) and (2), because :has means "has somewhere among all my descendants".
我需要的是:has,但意思是在我的直系子女中".
What I need is something like :has, but meaning "has among my direct children".
或者,一种向上横向的方式,例如仅选择当前选定元素的父级".
Alternatively, a way to transverse upwards, like "select only the parent of the currently selected element".
很抱歉,这个问题很简单,但是我似乎无法在API文档的任何地方找到它.
Sorry for the simple question, but I can't seem to find it anywhere in the API docs.
推荐答案
您尝试过$("td.ptextno:contains('Betreuung')").parent()
吗?
看起来问题的示例已更改...尝试$("td.special").parent()
众所周知,遍历文档位于此处: http://docs.jquery.com/Traversing
Looks like the question's example changed... try $("td.special").parent()
EDIT 2: Just so you know, the docs on traversing are here: http://docs.jquery.com/Traversing
这篇关于jQuery初学者::仅适用于直接后代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!