I'm building a fairly simple plugin with jQuery that validates a form. When an element is assessed to be valid I run
$(this).prop("valid", false);
In certain instances I'm going to want to block the form from submitting if anything is invalid. Essentially I'm looking for a way to select all the elements where the valid property is false? Am I going to have to iterate over all relevant elements and check for a false reading or is there a jQuery selector that I've overlooked? Something like:
$("input[valid=false]");
Would be nice. Any suggestions?
Try this...
$('input').filter(function() {
return this.valid === false;
});
It will return all input
elements (do you mean :input
?) where its valid
property is false
(notice strict equality comparison).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With