Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery - How to test if an input element has the valid or invalid pseudo-class applied?

Can you test if an input element has the CSS3 :valid or :invalid pseudo-class applied to it with jQuery? I would like to test if the form element passed the CSS validation before enabling a submit button.

Things I tried already that did not work:

if($("#el").is(":valid")) {
    //...
}

if($("#el:valid").length == 0) {
    //...
}

$("#el").attr("valid")
like image 830
jjclarkson Avatar asked Jan 15 '14 16:01

jjclarkson


1 Answers

After upgrading to jquery 1.10.2, I can confirm that using the :valid selector now works as expected.

if($("#el").is(":valid")) {
    //...
}
like image 157
jjclarkson Avatar answered Oct 28 '22 09:10

jjclarkson