I knew in js I can select this -> <div id='x'>xd</div>
element via document.getElementById('x')
or document.querySelector('#x')
, but today I discovered i can just select it writing x
like it’s a variable in my script already. The question is what is this method called and what is browser support?
Yes it is dependent on the browser (javascript engine), and i would recommend avoiding relying on such features in anything else than a proof of concept. I also recommend having a look at this https://www.tjvantoll.com/2012/07/19/dom-element-references-as-global-variables/