ElementInternals: form プロパティ
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
form
は ElementInternals
インターフェイスの読み取り専用プロパティで、この要素に関連付けられた HTMLFormElement
を返します。
値
HTMLFormElement
です。
例
次の例では、 ID が myForm
のフォーム内にカスタムチェックボックスコンポーネントを配置しています。
コンソールに form.length
を出力すると、 HTMLFormElement.length
という値が得られます。
html
<form id="myForm">
<custom-checkbox id="custom-checkbox"></custom-checkbox>
<custom-label for="custom-checkbox">Join newsletter</custom-label>
</form>
js
class CustomCheckbox extends HTMLElement {
static formAssociated = true;
#internals;
constructor() {
super();
this.#internals = this.attachInternals();
}
connectedCallback() {
console.log(this.#internals.form.length);
}
}
window.customElements.define("custom-checkbox", CustomCheckbox);
仕様書
Specification |
---|
HTML # dom-elementinternals-form |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
form |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.