Jquery every input hasClass

For my needs I use

$('#form :input').each( function(i) { if ( !$(this).hasClass('donot') ) { $(this).attr('disabled', 'disabled'); } }); 

is there a better way not to use the if condition to check if the input has the class "donot"?

Thank you for your help...

Chris

+8
jquery input each
source share
2 answers
 $('#form input:not(.donot)').each( function(i) { $(this).attr('disabled', 'disabled'); }); 

And here you are: -D

Documents for the selector :not()


Or you can also do:

 $('#form input').not('.donot').each( function(i) { $(this).attr('disabled', 'disabled'); }); 

Documents for .not()

+8
source share

Try this and you don’t even need every cycle to do this.

 $('#form input:not(.donot)').attr('disabled', 'disabled'); 
+2
source share

All Articles