html element id as javascript variable -


consider following code:

<html> <head></head> <body> <div id='test' class='blah'>   <a href='http://somesite.com/' id='somelink'>click!</a> </div> </body> </html> 

so discovered creates javascript object called somelink , can instance value of href attribute somelink.href. tested in latest chrome, ff , ie , works.

first off, how long has "feature" been around? imagine while, because have known years ids html elements on page must unique, , if have more 1 element sharing same id, last 1 overwrites previous one(s), , using instance getelementbyid() return last one. never understood why, now, looking @ "this creating object" perspective, makes sense. so, far being able directly access id-name-as-javascript object...how long has been around? ie6 era? earlier?

2nd...i guess more of discussion point question, but... imo doesn't seem "feature" have... isn't whole point of having dom , wrapper functions getelementbyid(), give organization , more importantly, cut down on namespace issues? don't feel should have worried random html elements on page overwriting javascript variables (something has happened, why discovered "feature"). know why is, what's logic behind it?

first off, how long has "feature" been around?

it microsoft-ism cropped around ie 4 if remember correctly.

some other browsers have added support in effort compatible badly written code depends on it. may support in quirks mode.

this doesn't seem "feature" have

correct. don't use it. :)


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -