ElementInternals.form
The form
read-only property of the ElementInternals
interface returns the HTMLFormElement
associated with this element.
Syntax
let form = ElementInternals.form;
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="join-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 (HTML) # dom-elementinternals-form |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
form |
77 |
79 |
No |
No |
64 |
No |
77 |
77 |
No |
55 |
No |
12.0 |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/form