I'm having an issue with the code below, the function is to find click on all links that contain ".gif". The code seems to iterate but only clicks the last iteration (when i=20), after some research it seems to be an issue with "hoisting" although Im unsure how to edit my code to fix the issue.
for (let i = 0; i < 20; i++) {
if (document.getElementsByTagName("a")[i].hasAttribute("href")) {
if (document.getElementsByTagName("a")[i].getAttribute("href").includes(".gif")) {
document.getElementsByTagName("a")[i].click();
}
}
}