I have this working function to order a list by the span content
var list = $("ul#videosList");
var desc= false;
list.append(list.children().get().sort(function(a, b) {
var aProp = $(a).find("span").text(),
bProp = $(b).find("span").text();
return (aProp > bProp ? 1 : aProp < bProp ? -1 : 0) * (desc ? -1 : 1);
}));
which I got it from here: Order ul list by span content
Now my question is, how do I reverse that function if one of the checkboxes is checked? And by reverse I mean to return it to its default state before ordering.
Just keep a reference to the original
list.children()object.Update:
I mean you should keep a reference like:
before, you make the call to
.get().sort(). The order of the elements inside$orig_orderwon’t change, no matter how they are attached in the DOM. So if you want to restore the original order at some point, you just append them to the list again: