Reputation: 435
For my needs I use
$('#form :input').each( function(i) {
if ( !$(this).hasClass('donot') ) {
$(this).attr('disabled', 'disabled');
}
});
is there a better way to not use the if condition to check if the input has the class 'donot' ?
Thanks for your help...
Chris
Upvotes: 8
Views: 16192
Reputation: 69915
Try this and also you don't even need each loop to do this.
$('#form input:not(.donot)').attr('disabled', 'disabled');
Upvotes: 3
Reputation: 146310
$('#form input:not(.donot)').each( function(i) {
$(this).attr('disabled', 'disabled');
});
And there you go :-D
Or you can also do:
$('#form input').not('.donot').each( function(i) {
$(this).attr('disabled', 'disabled');
});
Upvotes: 9