Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

279
Vistas
Is getElementById or getElementsByClassName[0] faster?

Is it faster to use getElementById

document.getElementById('foo').style.visibility = 'visible';

or getElementByClassName[0]

document.getElementsByClassName('foo')[0].style.visibility = 'visible';

I have read that too many IDs can hamper performance, which is why I am trying to shy away from IDs. But if it is faster to use an ID for a quick JavaScript lookup, I will gladly do so.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

getElementById would be the fastest method, since it's simple table lookup.

getElementsByClassName the same as querySelector almost twice as slow.

For best performance use ids for javascript and classes for CSS.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda