jQuery wrap code after x number of elements

后端 未结 4 1318
情话喂你
情话喂你 2020-12-09 00:51

I have a UL that contain any number of LIs. I am trying to create some jQuery code that will parse the original UL and wrap a UL and another LI after every 5 of the original

4条回答
  •  情书的邮戳
    2020-12-09 01:24

    jQuery('ul#original_ul').attr('id', 'processed_ul')
        .find('li:nth-child(5n)').each(function() {
            $(this).prevAll('li').andSelf()
                .wrapAll('
    • '); });

    提交回复
    热议问题