DOM Properties

HTMLFormElement.elements

Build a form with the HTML form generator

Read-only live collection. Exposes listed controls associated with the form, including eligible controls outside its subtree. It is live and supports indexed and named lookup. Historical exceptions include input type=image. Example result: 2.

Formal Syntax & Structure

html syntaxhtml
element.elements

Return Value

HTMLFormControlsCollection

Property value. Read-only live collection.

Working Example

Example Snippethtml
<form id="demo">  <input name="name"></form><input form="demo" name="extra"><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  result(e.elements.length);</script>
HTML Reference