HTMLOutputElement: htmlFor property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨August 2016⁩.

The read-only htmlFor property of the HTMLOutputElement returns a live DOMTokenList object containing a list of ids of those elements contributing input values to (or otherwise affected) the calculation. It reflects the <output> element's for content attribute.

Value

A live DOMTokenList object.

Although the htmlFor property itself is read-only in the sense that you can't replace the DOMTokenList object, you can still assign to the htmlFor property directly, which is equivalent to assigning to its value property. You can also modify the DOMTokenList object using the add(), remove(), replace(), and toggle() methods.

Examples

js
const outputElem = document.getElementById("result");
for (const id of outputElem.htmlFor.split(" ")) {
  const elem = document.getElementById(id);
  elem.style.outline = "2px solid red";
}

Specifications

Specification
HTML
# dom-output-htmlfor

Browser compatibility

See also