2014-08-27 40 views
0

我有3個CSS類A,B,CjQuery的不:選擇與OR

我想選擇「一個」,但不以任何「b」或「c」的 的其在類中的所有元素例如

class="a" <- select 
class="anyThing" <- do not select 
class="a anyThing" <- select 
class="a b" <- do not select 
class="a c" <- do not select 
class="a anything c" <- do not select 

這裏就是我想沒有成功:

$('.a:not(.b .c)')... 

我缺少什麼? 在此先感謝

+1

你試過$(」 A:不是(.B):不是(.C) ')? – 2014-08-27 11:36:32

+0

@Julien謝謝。請作爲答覆發佈,我會標記它。 – 2014-08-27 11:40:27

回答

1

使用這樣的:

$('.a').not('.a.b,.a.c') 

working fiddle

你也可以使用$( 'A ')不是(' A,.B。'),但有不同。

查看區別在這裏的小提琴:fiddle 1 | fiddle 2

所以,我想你會選擇1種方法。

+2

$('。a')。not('。a.b,.a.c')a也是這裏的一個類別.. – Vishwanath 2014-08-27 11:36:42

+1

對不起,我錯過了這個點。 – 2014-08-27 11:41:17

+0

a是類而不是標籤... – 2014-08-27 11:42:02

3

您需要內:not-selector

$('.a:not(.b, .c)')... 
+1

+1這是你想要的解決方案OP - [** JsFiddle示例**](http:// jsfiddle達網絡/ vwr4964g /) – urbz 2014-08-27 11:40:42