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

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -