Last Updated: February 25, 2016
· nashby

Accessing DOM node by id

If you have DOM node with id like

<div id="foo"></div>

you can access it by referring to the variable named according to the id of DOM node:


You can test it using Developer Tools in Chrome:

3 Responses
Add your response

Doesn't that mean ID-used words are reversed now (can't be used as variable names)?

over 1 year ago ·

Hey, you can read detailed explanation here

over 1 year ago ·

too much magic, can be clobbered by variables named the same as an element ID

over 1 year ago ·