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.