标签: javascript jquery
如果我有
$('.rotator li').each(function() { $(this).further-nested-elements.somefunction(); });
如何引用嵌套在this下面的元素,这样每次我想访问它时都不必继续重新键入原始选择器(即$('.rotator li'))?
this
$('.rotator li')
答案 0 :(得分:4)
使用.find():
.find()
$(this).find(".someClass");
或者,使用this作为context:
$(".someClass", this);
我更喜欢第二种方法,因为至少在我的脑海中,似乎它只需要做更少的工作 - 只有一个函数调用,只创建一个jQuery对象而不是两个。
答案 1 :(得分:1)
你可以使用:
$(this).children("further_selector")
或
$(this).find("further_selector")