One approach is to use jQuery of each method to load each of the sections into an array that you define earlier. Create your conditions in each method, collect data and do what your heart desires with each list.
With this method, you can set as many variables inside this method for each method. For example, if there is another attribute that you want to check inside each li element, you can do this and make more lists.
The .log console below simply gives you visual information about what is stored in each array you define. Good luck
And a quick jsFiddle demo.
var cat1 = []; var cat2 = []; var cat3 = []; $('li').each(function () { var attrvalue = $(this).attr('data-category'); if (attrvalue == "category-1") { cat1.push(attrvalue); } if (attrvalue == "category-2") { cat2.push(attrvalue); } if (attrvalue == "category-3") { cat3.push(attrvalue); } }); console.log('how many are here? :'+ cat1); console.log('how many are here? :'+ cat2); console.log('how many are here? :'+ cat3);
blackhawk
source share