1

Recently, I noticed that browsers automatically create variables to reference elements with id. For example, stackoverflow logo on this page

<div id="hlogo">
    <a href="/">Stack Overflow</a>
</div>

or question info at the right side

<table id="qinfo"></table>

You can access these by just using their id. Try it on the console.

What I want to know is that when was this feature (if it's) implemented? What of its future? Where can I find the documentation?

akinuri
  • 10,690
  • 10
  • 65
  • 102
  • As best I know, it's an undocumented convention started by one browser, then followed by some others. I consider it unsafe to rely on because any global variable by that name will trounce this use and because I don't think it's documented by any standard. – jfriend00 Aug 17 '14 at 18:09
  • Have a look at [Should the id of elements be made global variables?](http://stackoverflow.com/questions/6381425/should-the-id-of-elements-be-made-global-variables-and) – Volune Aug 17 '14 at 18:10
  • [Named access on the window object](http://www.whatwg.org/specs/web-apps/current-work/#named-access-on-the-window-object) – Patrick Evans Aug 17 '14 at 18:10
  • Man. These questions go back to 2010. I'm so late to the party. – akinuri Aug 17 '14 at 18:16

2 Answers2

0

I dont think that you will find any documentation regarding when it was element. However if you want to know that how you can access element without an id then there are some methods like document.getElementsByClassName(Howevere beware that it is not supported by all the browsers.)

Also there are ways like this:

<div onclick='test(this)' class='test>
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

the selection has been used in javascript for a long time by using

document.getElementById("id") 

documentation :http://www.w3schools.com/jsref/met_doc_getelementbyid.asp

also the jquery library allows you to select item using '#' selector i.e.

$("#id")

documentation : http://api.jquery.com/id-selector/

user3260861
  • 149
  • 6