ElementInternals.form

The form read-only property of the ElementInternals interface returns the HTMLFormElement associated with this element.

Value

An HTMLFormElement.

Examples

The following example shows a custom checkbox component inside a form with an ID of myForm. Printing form.length to the console, gives us the value of HTMLFormElement.length.

<form id="myForm"><custom-checkbox id="custom-checkbox"></custom-checkbox>
  <custom-label for="custom-checkbox">Join newsletter</custom-label></form>
class CustomCheckbox extends HTMLElement {
  static formAssociated = true;

  constructor() {
    super();
    this.internals_ = this.attachInternals();
  }

  /* ... */

  window.customElements.define("custom-checkbox", CustomCheckbox);
})();

let element = document.getElementById("custom-checkbox");
console.log(element.internals_.form.length);

Specifications

Specification
HTML Standard
# dom-elementinternals-form

Browser compatibility

BCD tables only load in the browser