Document.querySelectorAll in a looping

Asked

Viewed 12 times

2

var linksMenu = document.querySelectorAll(".links-menu");

for (var i = 0; i<linksMenu.length; i++) {
    linksMenu[i].addEventListener("click",function() {
        console.log(linksMenu[i]);
    });
}

I cannot show the position it was clicked on, in the case, it appears as Undefined.

However, if you put any console.log, it works exactly in the clicked position, so it’s functional.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.