Reputation: 5859
How do i select the nth-child plus the rest of div.containers i tried nextAll but that skips the nth-child
$('.container nth-child(' + index + ')').nextAll().each(function() {
//problem here in selecting the next index ^^ plus the rest of div.container
});
<div>
<div class="container" style="width:220px; height:220px; z-index:999; position:absolute; background-color:Aqua; float:left">
<div class="menu-item">Menu Item 1</div>
<div class="menu-item">Menu Item 2</div>
<div class="menu-item">Menu Item 3</div>
</div>
<div class="container" style="width:200px; height:200px; z-index:998; position:absolute; background-color:Blue; float:left">
<div class="menu-item">Menu Item 4</div>
<div class="menu-item">Menu Item 5</div>
<div class="menu-item">Menu Item 6</div>
</div>
<div class="container" style="width:180px; height:180px; z-index:997; position:absolute; background-color:Fuchsia; float:left">
<div class="menu-item">Menu Item 7</div>
<div class="menu-item">Menu Item 8</div>
<div class="menu-item">Menu Item 9</div>
</div>
<div class="container" style="width:160px; height:160px; z-index:997; position:absolute; background-color:Green; float:left">
<div class="menu-item">Menu Item 10</div>
<div class="menu-item">Menu Item 11</div>
<div class="menu-item">Menu Item 12</div>
</div>
</div>
Upvotes: 1
Views: 612
Reputation: 148
Yes, you need to add the selector .andSelf() to the end before the each to include the original selector like this:
$('.container nth-child(' + index + ')').nextAll().andSelf().each(function()
that should do it for you. Here's the jQuery reference: http://api.jquery.com/andSelf/
Upvotes: 3