This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2016.
The htmlFor property of the HTMLOutputElement interface is a string containing a space-separated list of other elements' ids, indicating that those elements contributed input values to (or otherwise affected) the calculation. It reflects the for attribute of the <output> element.
A string.
const outputElem = document.getElementById("result");
for (const id of outputElem.htmlFor.split(" ")) {
const elem = document.getElementById(id);
elem.style.outline = "2px solid red";
}
| Specification |
|---|
| HTML> # dom-output-htmlfor> |
| 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 |
9Before Chrome 50, this property returned the deprecated childDOMSettableTokenList instead of DOMTokenList. |
14 | 4 | 15Before Opera 37, this property returned the deprecated childDOMSettableTokenList instead of DOMTokenList. |
5.1 | 18Before Chrome Android 50, this property returned the deprecated childDOMSettableTokenList instead of DOMTokenList. |
4 | 14Before Opera Android 37, this property returned the deprecated childDOMSettableTokenList instead of DOMTokenList. |
5 | 1.0Before Samsung Internet 5.0, this property returned the deprecated childDOMSettableTokenList instead of DOMTokenList. |
3Before Chrome 50, this property returned the deprecated childDOMSettableTokenList instead of DOMTokenList. |
5 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement/htmlFor