DOM Properties
HTMLLabelElement.control
Read-only. Returns the control associated with a label, or null when no eligible control is associated. This can be used to diagnose broken for/id links without replacing native label semantics. Example result: field.
Formal Syntax & Structure
html syntaxhtml
element.controlReturn Value
HTMLElement or null
Property value. Read-only.
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>