ElementInternals: checkValidity() method
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
- constraint validation rules applied to it.
If
checkValidity
returnsfalse
then a cancelable invalid event is fired on the element.
Syntax
checkValidity()
Parameters
None.
Return value
A boolean value, true
if the element meets all validation constraints.
Exceptions
NotSupportedError
DOMException
-
Thrown if the element does not have its
formAssociated
property set totrue
.
Examples
In the following example ElementInternals.setValidity()
is used to indicate that the element does not meet validation rules. Calling checkValidity()
returns false
. After calling setValidity
again, this time indicating that all rules are marked false, checkValidity()
returns true
.
let element = document.getElementById("join-checkbox");
element.internals_.setValidity({ valueMissing: true }, "my message");
console.log(element.internals_.checkValidity()); / false
element.internals_.setValidity({});
console.log(element.internals_.checkValidity()); / true
Specifications
Specification |
---|
Product helpcheckValidity() method of the DOMException \nThrown if the element does not have its In the following example Instance methodsRelated pages for Web Components |