在里面 子选择器的jQuery文档 我看到了这个说明:
注意:
$("> elem", context)
选择器将在以后的版本中弃用。因此不鼓励使用其替代选择器。
我一直使用这种模式,通常是这样的:
$nodes.find('> children[something=morecomplicated] > somethingelse');
但是,我不明白他们所指的“替代选择者”是什么。 编写遍历上下文节点的直接子节点的选择器的正确方法是什么? 作为奖励,任何人都可以解释 为什么 这是折旧的吗?每个人都给予的所有选择似乎都令人惊讶 丑陋。
这是一些事情 别 工作:
// does not guarantee that '.child' is an immediate child
$nodes.find('.child > .grandchild');
// this will return empty array in recent jQuery
// and will return full list of children in older jQuery
$nodes.children('.child > .grandchild');
// Anything like this which forces you to split up the selector.
// This is ugly and inconsistent with usual selector ease-of-use,
// and is a non-trivial conversion for long or complex selectors.
$nodes.children('.child').children('.grandchild');
// After all, no one would ever recommend
$nodes.find('.this').children('.that');
// instead of
$nodes.find('.this > .that');