How to access every third html element via js?
-
The loop should check for every third element, and make a check that the digit that is responsible for the ordinal number of the element was a multiple of threeJavaScript Chloe Brandt, Jan 1, 2020
-
Hello,
Did you get the list of items in an array?
Multiplicity check is performed through the operator " remainder of division ", for example, if we have a variable in loop i, it will be written like this
if (i%3==0) {
// выполняется для каждого i, кратного трём
}Anonymous -
const elements = Array
.from(document.querySelectorAll('селектор элементов'))
.filter((n, i) => !(i % 3));Chloe Luna -
const result = document.querySelectorAll('...:nth-child(3n)');
Anonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!