Jquery for loop write html after every third iteration of loop

后端 未结 2 1499
星月不相逢
星月不相逢 2021-02-05 16:14

I am trying to get a

to appear after every third iteration of a for loop in jquery. I know in PHP it can be accomplished vi
2条回答
  •  误落风尘
    2021-02-05 16:48

    Use the modulus operator instead.

    if ( i && (i % 3 === 0)) { ...
    

    Whenever there's no remainder, you're evenly divisible by 3.

    I included the i && to eliminate the first iteration since 0 % 3 === 0; // true.

提交回复
热议问题