DOM Properties

ElementInternals.form

Build a form with the HTML form generator

Returns the current form owner or null. Association can change when the element moves or form attributes change. A form-associated custom element can inspect its current owner, including a form identified by the form attribute. Read the property again after association changes. A custom element that is not form-associated cannot use this form API. Example result: demo-form.

Formal Syntax & Structure

html syntaxhtml
internals.form

Return Value

HTMLFormElement | null

Current HTMLFormElement owner, or null when unassociated.

Working Example

Example Snippethtml
<form id="demo-form">  <demo-field name="city"></demo-field></form><p>  Result:  <output id="result"></output></p><script>  const result = document.getElementById("result");  (async () => {  class DemoField extends HTMLElement { static formAssociated = true; constructor() { super(); this.internals = this.attachInternals(); } }  customElements.define("demo-field", DemoField);  const field = document.querySelector("demo-field"); const internals = field.internals;  result.textContent = internals.form.id;  })().catch(error => { result.textContent = "Error: " + error.name; });</script>
HTML Reference