在jQuery中选择父母的下一个兄弟姐妹的孩子 [英] Selecting parent's next sibling's children in jQuery

查看:81
本文介绍了在jQuery中选择父母的下一个兄弟姐妹的孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的DOM的一部分的说明:

This is an illustration of a part of my DOM:

我想在类为butdiv点击事件中触发类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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆