jQuery: How to find elements *without* a class set

Posted by Alan on Stack Overflow See other posts from Stack Overflow or by Alan
Published on 2010-04-26T17:06:56Z Indexed on 2010/04/26 17:13 UTC
Read the original article Hit count: 240

Filed under:
|

Hey jQuery clever peeps,

Why does this fail...

$( 'div.contactAperson input' ).not( 'input.hadFocus' ).focus(function() {
    $(this).attr('value', '' );
});

...it's meant to sniff out input's that have not got the class .hadFocus and then when one of that subset receives focus it should zap the value to null.

Right now, input values are always getting zapped -- the test .not( 'input.hadFocus' ) is failing to stop execution.

Btw, preceding the above code is the following code, which is working fine:

$( 'div.contactAperson input' ).focus(function() {
    $( this ).addClass( 'hadFocus' );
});

Thanks for any cleverness - cheers, -Alan

© Stack Overflow or respective owner

Related posts about jquery-selectors

Related posts about not