I’m thring to convert this code to vanilla JavaScript without jQuery:
if ($(el).is(":invalid")) {
// etc
}
How do I write this code without using JavaScript?
I tried looking at youmightnotneedjquery.com , but it doesn’t seem to have this use-case.
2
Answers
You can use the
matches
function, and pass to it any CSS selector that would work with any pseudo-class, including:invalid
:You can simply check the ‘validity.valid’ property of the element.
Read more about this property on MDN