.slice and .wrapall

后端 未结 2 414
陌清茗
陌清茗 2021-01-18 21:43

I\'m using a bit of code suggested by a member on stackoverflow and adapted by me to wrap every 3 list items as part of a mega menu. The code is:

var lis = $         


        
2条回答
  •  温柔的废话
    2021-01-18 22:08

    have you tried applying it withe the use of the class as ht selector like this?

    var lis = $("ul.list-content > li");
    for(var i = 0; i < lis.length; i+=3) {
      lis.slice(i, i+3).wrapAll("
    "); }

    But if you did not know, I'm warning you that you are breaking the dom.. you are putting div on ul which is not good.. ;)

提交回复
热议问题