Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to select all elements with a certain property value?

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?

like image 559
Dormouse Avatar asked Dec 27 '22 20:12

Dormouse


1 Answers

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).

like image 149
alex Avatar answered Jan 12 '23 00:01

alex