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

179
Vistas
What makes those two invocations of addEventListener differ, resulting in one having an effect and the other not?

I was trying to write a Greasemonkey script that hooks to onclick of a specific element. Here's the code that doesn't work (seems to be ignored silently, has no observable effect):

img = document.evaluate('//img [@title="Play / Pause"]', document.body).iterateNext()
result = img.addEventListener("click", OnPlay)

On one chat, I got a similar, but working solution:

Array.from(document.querySelectorAll('img[title="Play / Pause"]')).forEach(elem => elem.addEventListener("click", OnPlay))

Apart from one being functional and the other imperative, what made one of them work and the other one not? The console seems to give me no clues.

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

0

I was just poking in the dark which did contain the answer though. So, that the question does not remain answerless, I'm adding this.

The issue apparently was that both scripts are not equivalent, and the iterateNext() only returns one element and not multiple.

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