HTMLOutputElement: htmlFor property

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) {
  const elem = document.getElementById(id);
  elem.style.outline = "2px solid red";
}

Specifications

See also