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

178
Vistas
Why doesn't my code work with querySelectorAll?

When I try to create a simple alert by using document.querySelector('.custom'), my code functions properly and returns the dataset of first img but doesn't for the other line(s) although I change the JS into document.querySelectorAll('.custom')

I'm sure it's kids' stuff for most but I couldn't find the solution though. Thanks in advance for your help.

const custom = document.querySelectorAll('.custom');
custom.addEventListener('click', function() {
    alert(`Welcome ${custom.dataset.name} ${custom.dataset.last}`);
});
<div class="item">
      <img data-name="name 1" data-last="last 1" class="custom" src="https://source.unsplash.com/random/300x300" />
      <img data-name="name 2" data-last="last 2" class="custom" src="https://source.unsplash.com/random/300x300" />
      <p>Hi I'm a item</p>
    </div>

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