How to find an element outside its parent using jQuery

I have this markup:

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

Now I need to find the next panel right on the right for the button element and do some action on it. So I do this, but something is wrong, can someone help?

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

Thanks for reference.

+4
source share
3 answers

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

+6
source

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

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

You can do it:

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

Source: https://habr.com/ru/post/1490893/


All Articles