据我所知,有很多方法可以在jQuery中 Select 子元素.
//Store parent in a variable
var $parent = $("#parent");
Method 1 (by using a scope)
$(".child", $parent).show();
Method 2 (the find() method)
$parent.find(".child").show();
Method 3 (For immediate children only)
$parent.children(".child").show();
Method 4 (via CSS selector)-由@spinon建议
$("#parent > .child").show();
Method 5 (identical to 101)-根据@Kai
$("#parent .child").show();
I'm not familiar with profiling to be able to investigate this on my own, so I would love to see what you have to say.
另外,我知道这可能是this question的复制品,但它不包括所有方法.