javascript - Wrapping Elements Based on Loop, Plus Amount of Modulus -


After

I have every third example of a & lt is needed to wrap; Div & gt; Dynamically in some HTML, and, if there is any remaining, in that way to wrap the amount of less than three in a similar way, then it will serve as the last example of "wrap". Taking every third example is very basic:

  var divs = $ (". Someclass"); Var range = 10; For (; I & lt; boundary; above i = 0 i + = 3) {divs.slice (i, i + 3) .wrapAll ("

However, because there is 1 remaining in this example, and I'm dynamically creating HTML somewhere else (here it is very complex for demo, but this aspect works fine It does the result, this example sets four ".classwrap" divs, sets three ".someclass" divs, giving me twelve ".someclass" divs, not ten what I'm trying to get in this example I really have four sets of ".classwrap" divs, but those wrapper sets With each three containing ".someclass" divs, and after that the first three quarters with a ".classwrap" div getting indicated that as the boundary variable indicated, only one ".someclass" div, ten ".someclass" divs It is meant for greatness.

I try to loop my loop but it sits somewhere in a modulus operator, always throws the math and wrapping accordingly. With any help you can provide me here. Would be greatly appreciated.

These answers I think you are looking for. You need to decide when the last group is making. Then use the Modo value to wrap several sections.

  var divs = $ (".click"); Var range = 10; // divs.length; Var Grooper = 3 var modo = limit% grouper; (Var i = 0; i & lt; border; i + = grouper) for {var offset = grouper; If (modo + i === border) {offset = modo; } Divs.slice .wrapAll (I, I offset +) ("; div class = 'classwrap' style = & lt 'background color: #def;' & gt; & lt; / div & gt;); }   

OR

Replace your initial selection with:

  var limit = 10; Var divs = $ (".click") Piece (0, border);    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -