0

I wanted to know if its new feature or just a working bug

Before I used to do like

HTML :

<div id="identity">I am an demo text</div>

JS :

let iddiv = document.getElementById("identity");
console.log(iddiv)

but Now I can do

console.log(identity)

Withour storing the element in a variable

I just wanted to ask if it is fine !!

console.log(identity)
<div id="identity">I am an demo text</div>
Saurav
  • 36
  • 5
  • 3
    Do not rely on elements with an id being available as global variables. It may clash with other variables. Stick to using `document.getElementById()` – Ruan Mendes Jun 01 '22 at 14:47
  • 3
    It is an _old_ feature and comes with many pitfalls and problems, so you should rather not use it. – CherryDT Jun 01 '22 at 14:47
  • 2
    @CherryDT Yeah. In general, don't trust anything that crawled out of IE. – VLAZ Jun 01 '22 at 14:47
  • 1
    @VLAZ - You mean like `querySelectorAll`? ;-) Until they came to an abrupt halt once IE6 came out, Microsoft were actually innovating in the browser space. Then, of course, they went very dark. :-D – T.J. Crowder Jun 01 '22 at 14:55
  • 2
    @T.J.Crowder well, *in general*. There are exceptions, of course but most of the time you should be on your guard. – VLAZ Jun 01 '22 at 14:58

0 Answers0