jQuery:选择祖父母 [英] jQuery: selecting grandparents
本文介绍了jQuery:选择祖父母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有更好的方法来选择jQuery中的祖父母元素以避免这种情况?
Is there a better way to select grandparent elements in jQuery in order to avoid this ?
$(this).parent().parent().parent().parent().parent().children(".title, .meta").fadeIn("fast");
谢谢.
推荐答案
您可以使用parents()
方法,该方法将父对象与选择器进行匹配
You can use the parents()
method which matches parents against a selector
http://api.jquery.com/parents/
或者,如果您使用的是1.4,则有一个新的parentsUntil()
方法
Or if you're using 1.4 there is a new parentsUntil()
method
http://api.jquery.com/parentsUntil/
这篇关于jQuery:选择祖父母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文