HTML element is represented in JavaScript as a global variable , How?

Viewed 184

Does JavaScript represent each HTML element as a global variable which name is the id of the element ?

Let's say I have a hidden input element like this:

<input type="hidden" value="10" id="myInput" />

so I can access it in JavaScript :

console.log(myInput.value);

I tried it in chrome and firefox, and it worked for me.

My question is :

  • Is this issue new in JavaScript ?
  • Is it the best practice to get an element by id ?
  • Why they implement this functionality although using global variables is not the best practice?
1 Answers
Related