在jQuery中选择父母的下一个兄弟姐妹的孩子 [英] Selecting parent's next sibling's children in jQuery
问题描述
这是我的DOM的一部分的说明:
This is an illustration of a part of my DOM:
我想在类为but
的div
点击事件中触发类div为des
的div(在上一个偶数div
中)
I want to trigger an effect on div with class des
(which is in an odd div
) on click event of div
with class but
(which is in the previous even div
)
如何从but
中选择des
?
推荐答案
通常,如果this
是单击的.but
元素,则:
Trivially, if this
is the clicked .but
element:
$(this).parent().next().children('.des')
这确实假定没有其他元素,即.even
和.odd
元素是直接同级,并且.but
和.des
是它们各自.even
和.odd
祖先.
This does assume that there are no other elements in the way, i.e. that the .even
and .odd
elements are immediate siblings, and that .but
and .des
are immediately children of their respective .even
and .odd
ancestors.
效率较低,但保证可以与树中任意数量的其他(不匹配)元素一起使用
Less efficiently, but guaranteed to work with any arbitrary number of additional (non-matching) elements in the tree would be:
$(this).closest('.even').nextAll('.odd').first().find('.des')
这篇关于在jQuery中选择父母的下一个兄弟姐妹的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!