简体   繁体   中英

how to restart a foreach loop in js;

$('.thumb').each(function(i){ 
                if(i>= 4){
                    $(this).addClass('col-' + (i));
                }{
            $(this).addClass('col-' + (i));

                }

and i want result like在此处输入图片说明

what i do to add this class

Use the modulo operator:

$('.thumb').each(function(i){ 
  $(this).addClass('cold-' + (i % 4));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM