Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLButtonElement
  4. validity

HTMLButtonElement: validity property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Thevalidity read-only property of theHTMLButtonElement interface returns aValidityState object that represents the validity states this element is in.

Value

AValidityState object.

Examples

The following example demonstrates that a<button> is in an invalid state when acustomError is set; in this state, thevalidityState'svalidity property isfalse, whilecheckValidity() returnstrue if the button'stype is not"submit", because such buttons are not candidates forconstraint validation.

js
const button = document.getElementById("myButton");button.setCustomValidity("This button is invalid.");const validityState = button.validity;console.log(validityState.valid); // falseconsole.log(validityState.customError); // trueconsole.log(button.checkValidity()); // false if the button is of the "submit" type, true otherwise

Specifications

Specification
HTML
# the-constraint-validation-api:dom-cva-validity

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp