Normally I select elements with an id via document.getElementById('idName'). But apparently you can also select them by name only 'idName'. I was not aware of this until recently. I wanted to know if this is a "bad practice" to select elements by their idName? I have already used the search engine and found nothing about select by id name. So here is my question now.

console.log(idName)
<div id="idName">Hello World</div>
I believe this is a bad practice because you can get yourself confused and cause conflicts with your own js variables.
I can't say it's Good or bad But
you should be very careful while using . This can cause many problems So I will recommend use in Small Projects only . (it's My personal recommendation )
Suppose Your JavaScript loads First then it will throw an error and none of the code will work
For more Information
just typing in 'idName' isn’t a “short form” of document.getElementById() It’s a reference to a global variable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With