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.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356

1 Answers1

12
$('a:not(.active)')

should work


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

Andy
  • 29,707
  • 9
  • 41
  • 58
  • 1
    this works with $('#parent').find('a:not(.active)'); as well? –  Sep 13 '11 at 10:03
  • 1
    @Andy: _"yours works as well"_, [for single classed elements](http://jsfiddle.net/Shef/EYUQu/). – Shef Sep 13 '11 at 10:04
  • 1
    @Commando: Yes, it works even with that! Or directly `$('#parent a:not(.active)');` – Shef Sep 13 '11 at 10:05
  • @Shef: right, this could work though :) $('a:not([class*="active"])') – Andy Sep 13 '11 at 10:15
  • @Andy: Yeah, but it's still Sizzle, so not much improvement with that. :) – Shef Sep 13 '11 at 10:25
  • @Shef: just a slightly different approach, closer to his original code :) – Andy Sep 13 '11 at 10:54
  • @Andy: Shef is right. Class name, in my case, might be: "class anotherClass andAnotherClassAsWell" :) –  Sep 13 '11 at 11:05