Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery get next element and all of its children

Tags:

jquery

How can I get the next div element and then all of its children?

<div class="1"></div>
<div class="2">
    <div class="child1"></div>
    <div class="child2"></div>
</div>
<div class="3">
    <div class="child1"></div>
</div>

so, if $(this) currently is class 1, how can i get to only class 2 and all of its children. And I can't reference it by its class name since i won't know what that is.

I'm basically looking to merge these 2 statements into 1.

$(this).next('div').animate({height : 'toggle'});
$(this).next('div *').animate({height : 'toggle'});
like image 674
Tim Joyce Avatar asked Oct 27 '11 19:10

Tim Joyce


1 Answers

$(this).next('div').children().andSelf().animate({height : 'toggle'});
like image 150
Matt Ball Avatar answered Nov 11 '22 22:11

Matt Ball