Greasy Fork is available in English.

§
Gönderildi: 16.11.2020
for (var i = 0; i < document.querySelectorAll("#showQuickReply").length; i++) {
this.addEventListener("click", function(){ document.querySelectorAll("#quickReply")[i].style.display = ''; });
}

How can I pass the variable number 'i' to the quickReply element?
The script above works well, but the number i isn't added to the advent listener
wOxxOmMod
§
Gönderildi: 17.11.2020

Either use let instead of var or use forEach or create a closure, more info: https://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example/

§
Gönderildi: 20.11.2020
Thanks, this worked.
But I didn't really understood how to implement this if I wanted to use forEach
wOxxOmMod
§
Gönderildi: 20.11.2020
Düzenlendi: 20.11.2020

To use forEach with querySelectorAll the only additional trick is to convert it to an array:

[...document.querySelectorAll("#showQuickReply")].forEach((el, i) => { ....... })

i will be the index.

§
Gönderildi: 20.11.2020
Thanks.
So it's the same as this
Array.from(document.querySelectorAll('a.Lightbox_AddEdit[class*="completed"]')).forEach(link => link.parentElement.parentElement.style.display = 'none');

Post reply

Sign in to post a reply.