I am trying to see if any inputs have the class “invalid” with JQuery.
$('#formId input').hasClass('invalid');
is returning false. Even after I’ve used .addClass('invalid') on an input and verified with Chrome’s DOM inspector that the class is present.
The below suggestions are not working. My markup is a little bit different than just form>input though.
Just use the class-name as a selector:
This will only operate on those elements that have that class, otherwise, as a conditional, you can use
length:You could also use
filter():Which will limit the selector to only those elements with that class, or:
To return those elements that do not have the invalid class-name.