DOM Interfaces

HTMLLegendElement

Build a form with the HTML form generator

Represents the caption of a fieldset and exposes the fieldset's associated form when applicable. Use the legend as the first child of its fieldset. It is not a general-purpose heading element. Example result: f.

Formal Syntax & Structure

html syntaxhtml
const element = document.getElementById('demo'); // HTMLLegendElement

Return Value

HTMLLegendElement

An existing HTML DOM object associated with the legend element in this example; this interface is a type, not a function return contract.

Working Example

Example Snippethtml
<form id="f">  <fieldset>    <legend id="demo">Profile</legend>  </fieldset></form><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  result(e.form.id);</script>
HTML Reference