Reputation: 10702
I have a page with many elements that have the same class attached to them:
<div class="everyDiv"></div>
<div class="everyDiv"></div>
<div class="everyDiv"></div>
<div class="everyDiv"></div>
...
I add additional classes based on filters the user chooses to hide/display them:
<div class="everyDiv hide1"></div>
<div class="everyDiv hide2"></div>
<div class="everyDiv hide3"></div>
<div class="everyDiv hide2 hide3"></div>
...
Now, I need to select a range (using slice()
) of the .everyDiv
elements that DON'T have any of the "hide" classse - .hide1 .hide2 .hide3
.
How can I do this with jQuery?
I've tried the following without success:
$("div.everyDiv").not(".hide1").not(".hide2").not(".hide3").slice(n1, n2);
$("div.everyDiv:not(.hide1):not(.hide2):not(.hide3)").slice(n1, n2);
This doesn't work either:
$("div.everyDiv:not(.hide1), div.everyDiv:not(.hide2), div.everyDiv:not(.hide3)").slice(n1, n2);
Basically, all of the "hide#" classes have CSS of display: none;
, so I need to select my specified range of the divs that aren't "hidden".
Upvotes: 4
Views: 6750
Reputation: 7802
this should do it:
$('div.everyDiv:not(.hide1, .hide2, .hide3)').hide();
as per comments: making it a little more obvious what the fiddle is doing: not it adds a class to all the ones that DON'T Have any of the hide classes. http://jsfiddle.net/s9uyk/2/
Upvotes: 15
Reputation: 41523
This works
$("div.everyDiv").not(".hide1, .hide2, .hide3")
It is successfully selecting the elements that DON'T have .hide1
, .hide2
, .hide3
. checkout my example at jsfiddle . It is successfully hiding the elements that don't match the criteria, leaving the ones that don't visible. In this case it leaves 1,2,3,4 visable, because they DO have the .hide1
, .hide2
, .hide3
classes.
Upvotes: 1
Reputation: 11175
$('div.everyDiv').not(".hide1, .hide2, .hide3")
with a working Jsfiddle demo
Upvotes: 2
Reputation: 26380
I think your selector is fine - you're just not doing anything with it. Try this:
$("div.everyDiv").not(".hide1").not(".hide2").not(".hide3").fadeOut(1000);
You can also simplify this selector:
$("div.everyDiv").not(".hide1, .hide2, .hide3").fadeOut(1000);
You can see it working here:
Upvotes: 0
Reputation: 146360
It seems to be working for me:
http://jsfiddle.net/maniator/mTkNL/
Upvotes: 0
Reputation: 18572
$("div.everyDiv:not(.hide1), div.everyDiv:not(.hide2), div.everyDiv:not(.hide3)");
Upvotes: 1