How to reset a loop jQuery -


ok, i've created div dynamically in jquery display blogposts.

<div class="blog-items">     <div class="blog-item"></div> </div>  

the jquery below adds class of nomargin remove margin on last block. how can reset loop starts again on new row. nomargin class applied remaining blocks.

here's jquery excerpt

var blogitemlength = $('.blog-item').length; if(blogitemlength > 2) {     $('.blog-item:gt(1)').removeclass("blog-item").addclass("blog-item_nomargin"); }    

hope makes sense, in advance.

i'd suggest, little understand of problem:

$('.blog-item').filter(function(i){     return (i + 1)%3 === 0; }).removeclass('blog-item').addclass('blog-item_nomargin'); 

this takes .blog-item elements, filters them keep third, sixth, ninth... elements, removes blog-item class-name , adds blog-item_nomargin class-name.

references:


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -