Lukas
Lukas

Reputation: 7734

How to find an element outside its parent with jQuery

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.

Upvotes: 5

Views: 12243

Answers (3)

xionutz2k
xionutz2k

Reputation: 729

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

Upvotes: 8

palaѕн
palaѕн

Reputation: 73926

You can do this:

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

Upvotes: 3

karim79
karim79

Reputation: 342675

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);
});

Upvotes: 3

Related Questions