Here’s my problem. I want a script that takes the first ten items from an <ul> list and moves them into list1, then takes the next ten and moves them to the second one, and the same for the third one.
I tried to do that using jQuery.each() but it won’t work.
<html>
<body>
<ul class="list">
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<ul class="list1"></ul>
<ul class="list2"></ul>
<ul class="list3"></ul>
</body>
</html>
Here is some javascript. It is a fixed working one.
function SortCats(ul){
var array = [];
//var lis = $("#CatNavi li");
//for (var i = 0; lis.length; i++){
// array.push(lis[i].html());
// lis[i].hide();
//}
var $altlis = $("#CatNavi li");
var $cat1 = $(".supercat1");
var $cat2 = $(".supercat2");
var $cat3 = $(".supercat3");
$altlis.each(function(index){
alert("Shit happens");
if (index < 10){
$cat1.append($(this));
alert("Shit happens");
}
else if (20 >= index > 10){
$cat2.append($(this));
}
else if (index > 20){
$cat3.append($(this));
}
});
}
You want to move first ten items of the main list (with class
list) to the other list with classlist1the following ten to the list with classlist2and so on?I propose such solution :