javascript - Selecting parent's next sibling's children in jQuery - Stack Overflow

This is an illustration of a part of my DOM:I want to trigger an effect on div with class des (which is

This is an illustration of a part of my DOM:

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)

How can I select des from but?

This is an illustration of a part of my DOM:

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)

How can I select des from but?

Share Improve this question edited Jan 25, 2015 at 21:00 Josh Crozier 241k56 gold badges400 silver badges313 bronze badges asked Jan 25, 2015 at 20:14 Prakhar ThakurPrakhar Thakur 1,2293 gold badges15 silver badges39 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

Trivially, if this is the clicked .but element:

$(this).parent().next().children('.des')

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')

It depends on your markup. Something like this should work, though:

$('.but').on('click', function () {
  $(this).closest('.even').next().find('.des');
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743778105a4505605.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信