html - re build ul and li tag with Jquery -


i try find way split ul tag showing 10 li tag per ul.

suppose have li 30 elements. script re build 3 ul , each ul has 10 li tag.

how can ?

suppose original :

<ul id="ul1" style="">     <li><a href="#"><span>adidas</span></a></li>     <li><a href="#"><span>jason markk</span></a></li>     <li>... 28 mores </li> </ul> 

jquery re build ul in 3 ul (10 li per ul):

<ul id="ul1" style="">     <li>10 times</li> </ul> <ul id="ul2" style="">     <li>10 times</li> </ul> <ul id="ul3" style="">     <li>10 times</li> </ul> 

please guide, thanks

you can this

var n = 5; var uls = $("#ul1 li").length / n; (i = 0; < uls; i++) {     var newul = $("<ul/>", { id: "ul" + (i + 2) });     $("ul").eq(i).after(newul);     newul.append(newul.prev().find("li:gt(" + (n - 1) + ")"));  } 

change value of n according need

fiddle


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -