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

198
Vistas
How to get all elements of a similar attribute using for each loop in Javascript

I have 4 divs with the class of .btn applied to all of them. I want to console.log each button and only expect 4 items to be printed out but this is what was printed out:

0
1
2
3
entries
keys
values
forEach
length
item

And this is my code:

const btns = document.querySelectorAll(".btn");

for(let btn in btns){
    console.log(btn)
}

I want to eventually be able to call methods like getAttribute() on each button to apply different styles but it is not letting me.

about 4 years ago · Juan Pablo Isaza
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