$("input").each(function() {
if ($(this).hasClass('valid')) {
// Do something
}
});
The Code above determines if input has a specified class. However, how could I change the if statement to make it do something when input doesn’t have a specified class?
You can do it inside with a
!negation like this:Or just use
:not()when selecting those elements, like this:This means your original code can also be slimmer (for when it does have the class), like this: