Reputation: 4944
<div class="a-1">
<div class="a-2">
<div class="a-3">
<div class="a-1 a-2">
<div class="a-2 a-3">
<div class="a-1 a-3">
<div class="a-1 a-2 a-3">
I am looking to do something like this:
$('.a-1').show().siblings([all those that do not belong to a-1]).hide();
Is there anyway to achieve this? The :not()
selector seems to be failing me because it's selecting the inverse of each element individually, resulting in a selection of all 7 DIVs.
Upvotes: 6
Views: 5693
Reputation: 1
Works fine,with $('.a-1').show().siblings(':not(.a-3)').hide(); the a-1,a-2 and a-1 a-2 will become hidden since you are using the sibling() menthod, otherwise with $('.a-1').not('.a-3').hide(); only a-1 and a-1 a-2 will hide. for details visit : http://mondalmrinmoy.blogspot.com/2018/07/jquery-selectors-few-advanced-notes.html
Upvotes: -1
Reputation: 34598
Not sure what your issue with :not()
was but this should work fine:
$('.a-1').show().siblings(':not(.a-1)').hide();
Upvotes: 10