0
Always when I need to select more than one element on a page it is not possible to use the querySelector()
isn’t it? Then we should resort to querySelectorAll()
. I’ve always used it the following way (img is just a hypothetical example):
img = document.querySelectorAll("img");
for (var i = 0; i < img.length; i++) {
console.log(img[i]);
}
But the other day in an argument with a friend, we come to an impasse, what if there are too many elements on a page? Couldn’t this cause problems for users who have slower computers? Something like an infinite loop does..
There is another way to interact with various elements with the same genre without having to worry if it will not end up disturbing my user’s navigation?
It depends on what you do within the for cycle, but this is the "normal" way to iterate lists of elements. You can write html with classes or using selectors with relatives to make the smallest selection.
– Sergio