Insert
for every 5 elements using Javascript

前端 未结 6 559
悲哀的现实
悲哀的现实 2020-12-31 17:49

I have a simple list of images that is being controlled via a CMS (ExpressionEngine). Like this:


      
6条回答
  •  一向
    一向 (楼主)
    2020-12-31 18:21

    You can just create a div for every fith element and move the links into them using the append method:

    var wrapper = $('.wrapper');
    var div;
    $('a', wrapper).each(function(i,e){
        if (i % 5 == 0) div = $('
    ').addClass('slide').appendTo(wrapper); div.append(e); });

    Demo: http://jsfiddle.net/Guffa/ybrxu/

提交回复
热议问题