Skip to main content

Command Palette

Search for a command to run...

Without using document.getElementById

Historic window object still retains features pertaining to the start of the Browsers era

Updated
1 min read
Without using document.getElementById
A
I am a web developer from Navi Mumbai. Mainly dealt with LAMP stack, now into Django and getting into Laravel and Cloud. Founder of nerul.in and gaali.in

A few weeks ago I was surprised at at the fact that something that seemed impossible was / is still possible.

I didn't realize that this was even possible in my 20+ years of web development. I even had a debate with my colleague about not using it that way but we weren't in sync.

Apparently - if you set in your HTML <input type="text" id="first_name" /> , you don't need to do document.getElementById('first_name').value - instead, you can directly call first_name.value !!!

https://codepen.io/anjanesh/pen/GRLJZrj

Apparently, this is still valid and is also in the HTML spec.

the value of the id content attribute for all HTML elements that have a non-empty id content attribute and are in a document tree with window's associated Document as their root.