Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore multiple classes using the :not selector?

I have this selector below where it ignores any li with the class show-all-boxes

$('.boxes li:not([class="show-all-boxes"]) input:checkbox') 

What is the best way of adding multiple classes to be ignored by the selector? An example of this that I thought would work but it doesn't is:

$('.boxes li:not([class="show-all-boxes, show-all-circles, show-all-triangles"]) input:checkbox') 
like image 807
Cecil Theodore Avatar asked Jan 02 '12 09:01

Cecil Theodore


People also ask

Can class selector have multiple classes?

We aren't limited to only two here, we can combine as many classes and IDs into a single selector as we want.

How do you exclude a class in CSS?

In CSS, to exclude a particular class, we can use the pseudo-class :not selector also known as negation pseudo-class or not selector. This selector is used to set the style to every element that is not the specified by given selector. Since it is used to prevent a specific items from list of selected items.

Can you chain not CSS?

There are no logical combinators with :not() , like and or or , but you can chain them, which is effectively like and . The :not() selector doesn't add any specificy by itself, but what is inside does, so :not(.

How do you select an element that does not have a specific class?

To select element that does not have specific class with JavaScript, we can use the document. querySelector method with the :not pseudoclass. const li = document. querySelector("li:not(.


2 Answers

The :not selector can take multiple CSS selectors as arguments ( http://api.jquery.com/not-selector ). E.g.

$('div:not(.a,.b)').empty() 

http://jsfiddle.net/HFfcP/

like image 52
Thong Kuah Avatar answered Sep 24 '22 18:09

Thong Kuah


try this :

$('.boxes li').not(".show-all-boxes, .show-all-circles, .show-all-triangles").find('input:checkbox') 
like image 35
redmoon7777 Avatar answered Sep 26 '22 18:09

redmoon7777