I have something like this :
JavaScript
x
8
1
<div>
2
<div class="productPage"></div>
3
<div>is hidden</div> // ***this content will be hidden
4
</div>
5
6
// *** this one will not become hidden.
7
<div>not hidden..</div>
8
using this:
JavaScript
1
2
1
$( ".productPage").nextAll().addClass( "hidden" );
2
This will hide only the content i marked on the code, means only childs of the same parent.
I need to hide every single thing after productPage
.
Advertisement
Answer
You should also go to parent and target the next divs.
JavaScript
1
2
1
$(".productPage").nextAll().addClass("hidden");
2
$(".productPage").parents("div").eq(0).nextAll().addClass("hidden");
JavaScript
1
3
1
.hidden {
2
display:none;
3
}
JavaScript
1
9
1
<div>
2
<div class="productPage"></div>
3
<div>is hidden</div> <!-- this content will be hidden -->
4
</div>
5
6
<!-- this one will not become hidden. -->
7
<div>not hidden..</div>
8
9
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>