Sleazy Fork is available in English.

§
Pubblicato: 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
§
Pubblicato: 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/

§
Pubblicato: 20/11/2020

Thanks, this worked.
But I didn't really understood how to implement this if I wanted to use forEach

wOxxOmMod
§
Pubblicato: 20/11/2020
Modificato: 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.

§
Pubblicato: 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');

Pubblica risposta

Accedi per pubblicare una risposta.