HTMLFormElement: length プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

HTMLFormElement.length は読み取り専用のプロパティで、 <form> 要素に含まれるコントロールの数を返します。

フォームのコントロールの一覧には elements プロパティを使用してアクセスすることができます。

これは <form> 要素の子孫である要素、および form プロパティを使用してフォームのメンバーになった要素の両方が含まれます。

このプロパティで扱われる要素は、 <button>, <fieldset>, <input> (ただし、 "image" 型のものは、歴史的な理由によって除外されます)、<object>, <output>, <select>, <textarea> です。

数値です。

js
if (document.getElementById("form1").length > 1) {
  // 複数のフォームコントロールがある場合
}

仕様書

Specification
HTML
# dom-form-length-dev

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
length

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support