Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

235
Visualizações
Javascript - Select element by id name

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.

enter image description here

 console.log(idName)
<div id="idName">Hello World</div>

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I believe this is a bad practice because you can get yourself confused and cause conflicts with your own js variables.

over 4 years ago · Santiago Trujillo Relatório

0

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda