Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 760
Lukas Avatar asked Jul 11 '13 12:07

Lukas


3 Answers

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

like image 80
xionutz2k Avatar answered Oct 03 '22 12:10

xionutz2k


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);
});
like image 37
karim79 Avatar answered Oct 03 '22 12:10

karim79


You can do this:

open_bt.on('click', function () {
    $(this).closest('div').next('.panel').slideDown(100);
});
like image 20
palaѕн Avatar answered Oct 03 '22 10:10

palaѕн