最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to find an element outside its parent with jQuery - Stack Overflow

programmeradmin6浏览0评论

I have this markup:

  <div>
    <div>
      <button class="button"></button>
    </div>
    <div class="panel">
    </div>
  </div>

Now i need to find next panel just right for button element and make some action on it. So i do this but something is not right, can anybody help?

var open_bt = $('.button');

open_bt.on('click',function(){
   $(this).parent().parent().next().child('.panel').slideDown(100);
});

Thx for help.

I have this markup:

  <div>
    <div>
      <button class="button"></button>
    </div>
    <div class="panel">
    </div>
  </div>

Now i need to find next panel just right for button element and make some action on it. So i do this but something is not right, can anybody help?

var open_bt = $('.button');

open_bt.on('click',function(){
   $(this).parent().parent().next().child('.panel').slideDown(100);
});

Thx for help.

Share Improve this question asked Jul 11, 2013 at 12:27 LukasLukas 7,73420 gold badges79 silver badges127 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 8

$(this).parent().next('.panel').slideDown(100); should do the trick

You just need to go up one level, and there is no child method:

open_bt.on('click',function(){
   $(this).parent().next('.panel').slideDown(100);
});

You can do this:

open_bt.on('click', function () {
    $(this).closest('div').next('.panel').slideDown(100);
});
发布评论

评论列表(0)

  1. 暂无评论