ajsie
ajsie

Reputation: 79686

the :not operator in jquery

i want to select all elements without a special class.

i used:

 $('body:not(.noFocusOnKeypress)').live('keyup' ...

but it didnt work. and i have no idea why.

Upvotes: 2

Views: 6022

Answers (2)

Jimmy
Jimmy

Reputation: 37081

Just remove body from your selector. As it stands, you are selecting all body elements that don't have that class, not all elements of any type that don't have that class. What you want is this:

$(':not(.noFocusOnKeypress)').live()

Note that this might be a fairly inefficient selector (I'm not familiar with the internals of the :not pseudo-class) and that it might improve performance to scope it a bit, like so:

$('#div-that-contains-these-elements :not(.noFocusOnKeypress)').live()

Upvotes: 3

Kobi
Kobi

Reputation: 138007

This should do it:

$(':not(.noFocusOnKeypress)').live

Upvotes: 3

Related Questions