Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!