DOM Interfaces

HTMLLabelElement

Build a form with the HTML form generator

Represents a label and exposes its associated control and form owner. A label associates through for/id or permitted nesting. It should identify the control rather than rely on a placeholder. Example result: field.

Formal Syntax & Structure

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

Return Value

HTMLLabelElement

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

Working Example

Example Snippethtml
<label id="demo" for="field">Name</label><input id="field"><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  result(e.control.id);</script>
HTML Reference