diff --git a/files/en-us/web/api/htmlbuttonelement/checkvalidity/index.md b/files/en-us/web/api/htmlbuttonelement/checkvalidity/index.md index c95b268c0201dcd..99c9ad21ac32c68 100644 --- a/files/en-us/web/api/htmlbuttonelement/checkvalidity/index.md +++ b/files/en-us/web/api/htmlbuttonelement/checkvalidity/index.md @@ -8,10 +8,10 @@ browser-compat: api.HTMLButtonElement.checkValidity {{APIRef("HTML DOM")}} -The **`checkValidity()`** method of the {{domxref("HTMLButtonElement")}} interface returns a boolean value which indicates if the element meets any [constraint validation](/en-US/docs/Web/HTML/Constraint_validation) rules applied to it. If false, the method also fires an {{domxref("HTMLElement/invalid_event", "invalid")}} event on the element. Because there's no default browser behavior for `checkValidity()`, canceling this `invalid` event has no effect. +The **`checkValidity()`** method of the {{domxref("HTMLButtonElement")}} interface returns a boolean value which indicates if the element meets any [constraint validation](/en-US/docs/Web/HTML/Constraint_validation) rules applied to it. If false, the method also fires an {{domxref("HTMLElement/invalid_event", "invalid")}} event on the element. Because there's no default browser behavior for `checkValidity()`, canceling this `invalid` event has no effect. It always returns true if the {{HTMLElement("button")}} element's {{domxref("HTMLButtonElement/type", "type")}} is `"button"` or `"reset"`, because such buttons are never candidates for [constraint validation](/en-US/docs/Web/HTML/Constraint_validation). > [!NOTE] -> An HTML {{htmlelement("button")}} element with a non-null {{domxref("HTMLButtonElement.validationMessage", "validationMessage")}} is considered invalid, will match the CSS {{cssxref(":invalid")}} pseudo-class, and will cause `checkValidity()` to return false. Use the {{domxref("HTMLButtonElement.setCustomValidity()")}} method to set the {{domxref("HTMLButtonElement.validationMessage")}} to the empty string to set the {{domxref("HTMLButtonElement.validity", "validity")}} state to be valid. +> An HTML {{htmlelement("button")}} element of the `"submit"` type with a non-null {{domxref("HTMLButtonElement.validationMessage", "validationMessage")}} is considered invalid, will match the CSS {{cssxref(":invalid")}} pseudo-class, and will cause `checkValidity()` to return false. Use the {{domxref("HTMLButtonElement.setCustomValidity()")}} method to set the {{domxref("HTMLButtonElement.validationMessage")}} to the empty string to set the {{domxref("HTMLButtonElement.validity", "validity")}} state to be valid. ## Syntax diff --git a/files/en-us/web/api/htmlbuttonelement/validity/index.md b/files/en-us/web/api/htmlbuttonelement/validity/index.md new file mode 100644 index 000000000000000..276f960ef5d9d2a --- /dev/null +++ b/files/en-us/web/api/htmlbuttonelement/validity/index.md @@ -0,0 +1,44 @@ +--- +title: "HTMLButtonElement: validity property" +short-title: validity +slug: Web/API/HTMLButtonElement/validity +page-type: web-api-instance-property +browser-compat: api.HTMLButtonElement.validity +--- + +{{APIRef("HTML DOM")}} + +The **`validity`** read-only property of the {{domxref("HTMLButtonElement")}} interface returns a {{domxref("ValidityState")}} object that represents the validity states this element is in. + +## Value + +A {{domxref("ValidityState")}} object. + +## Examples + +The following example demonstrates that a `