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