Jquery for loop write html after every third iteration of loop

后端 未结 2 1500
星月不相逢
星月不相逢 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.

    0 讨论(0)
  • 2021-02-05 16:59

    Use this... just like your PHP

    if (i % 3 == 0 ) 
    
    0 讨论(0)
提交回复
热议问题