How to access every third html element via js?

  • 0
    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 three
    JavaScript Chloe Brandt, Jan 1, 2020

  • 3 Answers
  • 0

    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, кратного трём

  • 0
    const elements = Array
    .from(document.querySelectorAll('селектор элементов'))
    .filter((n, i) => !(i % 3));
    Chloe Luna

  • 0
    const result = document.querySelectorAll('...:nth-child(3n)');

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!