jQuery选择器上下文问题 [英] jQuery selector context question
问题描述
我正在尝试进行以下选择:
I'm trying to do make the following selection:
$(".program", row)
其中row是包含两个表行的jQuery对象。其中一个tr有类程序。这个选择器似乎找不到它。但是以下工作:
Where "row" is a jQuery object containing two table rows. One of the tr's has the class 'program". This selector doesn't seem to find it. However the following works:
$(".title", row)
其中div.title是tr.program的后代。
where div.title is a descendant of tr.program.
如果我使用jQuery对象作为选择器上下文,我是否无法匹配该jQuery对象的顶级元素?
If I use a jQuery object as a selector context, am I not able to match top-level elements of that jQuery object?
谢谢,
-Morgan
推荐答案
看起来你正在尝试从已经选择的元素中选择元素(驻留在jQuery对象中)。
It looks like you're trying to select elements out of the ones you already have selected (residing in the jQuery object).
就jQuery而言,上下文就像指定一个父类一样 - 上下文是一个节点,它位于DOM树中你所寻找的位置。上下文是jQuery查找你指定的选择器的地方。
Context, as far as jQuery is concerned, is like specifying a parent - the context is a node somewhere ABOVE what you're looking for in the DOM tree. The context is where jQuery will look for the selector you've specified.
如果我对你要做的事情是正确的,那么这应该有效:
If I am correct about what you're attempting to do then this should work:
row.filter('.program');
// And then:
row.filter('.program').find('.title');
这篇关于jQuery选择器上下文问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!