开发者

jQuery 5 elements create a new one the wrap the next 5 in

I have a central wrap and within that wrap I want to append a wrap which contains 5 items in it, but for every 5th time through the loop I want to add another wrapper for 5 more ele开发者_StackOverflow中文版ments then continue down the line..

My Issue is I'm not exactly sure how to catch the newly added container for every 5th set of items.. this is my current approach that I am stuck in..

var workSpaceItem = '<div class="ztsWorkSpaceItem" style="width:114px;height:33px;border:#000 solid 1px;color:#FFF;float:left;"></div>'
$.each(workSpaceJSON.workSpace, function(e)
{
    if(e %5 === 0){$('#ztsWorkspaceBarCenter').append('<div class="ztsWorkSpaceItem"></div>');alert('five: '+e);}
});


You may store it in a variable(called "wrapper" in the example):

    var workSpaceItem = '<div class="ztsWorkSpaceItem" style="width:114px;border:#000 solid 1px;float:left;"></div>'
    var wrapper;

    $.each(workSpaceJSON.workSpace, function(e)
    {
      if(e %5 === 0){wrapper=$(workSpaceItem).appendTo('#ztsWorkspaceBarCenter');}
      wrapper.append('<p>'+e+'</p>');
    });


Demo: http://jsfiddle.net/doktormolle/kF8tB/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜