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

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
htmlFor
Chrome – Full support
Chrome 9 (Release date: 2011-02-03)
footnote
footnote Before Chrome 50, this property returned the deprecated child DOMSettableTokenList instead of DOMTokenList.
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 4 (Release date: 2011-03-22)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote
footnote Before Opera 37, this property returned the deprecated child DOMSettableTokenList instead of DOMTokenList.
Safari – Full support
Safari 5.1 (Release date: 2011-07-20)
footnote Full support
Chrome Android – Full support
Chrome Android 18 (Release date: 2012-06-27)
footnote
footnote Before Chrome Android 50, this property returned the deprecated child DOMSettableTokenList instead of DOMTokenList.
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 14 (Release date: 2013-05-21)
footnote
footnote Before Opera Android 37, this property returned the deprecated child DOMSettableTokenList instead of DOMTokenList.
Safari on iOS – Full support
Safari on iOS 5 (Release date: 2011-10-12)
footnote Full support
Samsung Internet – Full support
Samsung Internet 1 (Release date: 2013-04-27)
footnote
footnote Before Samsung Internet 5.0, this property returned the deprecated child DOMSettableTokenList instead of DOMTokenList.
WebView Android – Full support
WebView Android 3 (Release date: 2011-02-22)
footnote
footnote Before Chrome 50, this property returned the deprecated child DOMSettableTokenList instead of DOMTokenList.
WebView on iOS – Full support
WebView on iOS 5 (Release date: 2011-10-12)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

See also