as you might know, within the HTML5 spec we got some new attributes for <input> elements, such as required and pattern. This provides as a great way of validating user-input and we can even visualize it using CSS and pseudo selectors. Example
HTML
<input type="number" pattern="\d+" required/>
CSS
input:required:valid {
border: 1px solid green;
}
input:required:invalid {
border: 1px solid red;
}
If that <input> element would be part of an <form> element, an user wouldn't be able to submit that in invalid state.
However, my question is, what if we want to use those new attributes without <form> elements ? Is there a way to access the current state of such an <input> node through ECMAscript directly ?
Any event ? Any listener ?
current state, you mean a JS way to check the validity of the input (As a property instead of a function you'd have to write)?validityStateproperty, but I don't know whether being outside a<form>breaks anything.validitynotvalidityState, sorry.