How to select an element which doesn't have a specific class name, using jQuery?
Asked Answered
M

1

11

How could a Commando, like myself, select an element witch does not have a class named "active", using the infamous and powerful jQuery Sizzle CSS and everything else - Selector?

I've tried with:

$('a[class!="active"]').etc();

But it gives no adequate results.

Mentality answered 13/9, 2011 at 9:58 Comment(0)
G
12
$('a:not(.active)')

should work


yours works as well. just tested: http://jsfiddle.net/UP6a7/

Gause answered 13/9, 2011 at 10:0 Comment(7)
this works with $('#parent').find('a:not(.active)'); as well?Mentality
@Andy: "yours works as well", for single classed elements.Roadbed
@Commando: Yes, it works even with that! Or directly $('#parent a:not(.active)');Roadbed
@Shef: right, this could work though :) $('a:not([class*="active"])')Gause
@Andy: Yeah, but it's still Sizzle, so not much improvement with that. :)Roadbed
@Shef: just a slightly different approach, closer to his original code :)Gause
@Andy: Shef is right. Class name, in my case, might be: "class anotherClass andAnotherClassAsWell" :)Mentality

© 2022 - 2024 — McMap. All rights reserved.