jQuery:$的直接子(这个)
是否有可能以某种方式选择$(this)的直接孩子?
我有:
var obj = $(this); $("ul", obj).css('width',s*w);
并且需要它像这样obj > ul
可能吗?
$(this).children('ul')
返回直接子项列表。
请尝试以下方法:
$(this).find("> ul")
jQuery构造函数可以使用第二个参数,该参数可用于覆盖选择的上下文。
$("ul", this);
如果你只想要第一个,我认为你可以做到
$("ul:first", this)
这可能也有效(取决于你可能的具体情况)
$(this).find('>*:eq(0)')
这对我有用;)
$('> ul',this)