10 ms·
TIL: DOM elements with IDs are automatically available as properties of window. (ball, paddle, etc.)
by dkordik 13y ago
TIL: DOM elements with IDs are automatically available as properties of window. (ball, paddle, etc.)
- dmak 13y agoI was surprised too. I thought you would have to explicitly select it with getElementById()
- jonahx 13y agoMe too. Anyone know what browser support is like?
- dkordik 13y agoA couple of findings: - This stackoverflow answer has a good back story on this: (TLDR, it's not standard... yet) http://stackoverflow.com/a/3434388/1339100 http://stackoverflow.com/a/3434388/1339100 but it is in this HTML 5.1 draft: http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object http://www.w3.org/html/wg/drafts/html/master/browsers.html#n... - It's slower than document.getElementById, somehow: http://jsperf.com/implicit-dom-element-variables http://jsperf.com/implicit-dom-element-variables