Last Updated: February 25, 2016
·
1.584K
· 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:

alert(foo)

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 http://stackoverflow.com/a/3434388/336626

over 1 year ago ·

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

over 1 year ago ·