HTMLSelectElement: 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 December 2018.

The validity read-only property of the HTMLSelectElement interface returns a ValidityState object that represents the validity states this element is in.

Value

A ValidityState object.

Example

The following example gets the validity state of a select element and processes it if it is not valid:

js
const select = document.getElementById("mySelect");
const validityState = select.validity;
if (!validityState.valid) {
  // Test each validity state
}

Specifications

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

Browser compatibility

BCD tables only load in the browser

See also