/ Published in: JavaScript
Sorts a list by its 'data-' attribute. Customization is very easy.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
(function () { var lis_bucket = [], lis_list = $('li.tab-list-item'), list_length = lis_list.length, ul = $('.events-content'), today = new Date(), i = 0; for (i = 0; i < list_length; i += 1) { lis_bucket[i] = []; lis_bucket[i][0] = new Date($(lis_list[i]).attr('data-date')); lis_bucket[i][1] = $(lis_list[i]).remove(); } lis_bucket.sort(function (a, b) { return a[0] - b[0]; }); for (i = 0; i < list_length; i += 1) { if (today < lis_bucket[i][0]){ ul.append(lis_bucket[i][1]); } } }());