Question

I have an unordered list and then the ordered ascendant descending and return to the initial state with a single button, this is what I have for now, thanks

http://jsbin.com/eculis/1405/

passed through three states, ascending, descending, and restore, its need

Was it helpful?

Solution

You need to modify your dec_sort function, just switch the order of the a and b argument variables.

function dec_sort(a, b){ //instead of b, a
    return ($(b).text()) > ($(a).text()) ? 1 : -1;    
}

Also, store the contents of your .list tag:

var original = $('.list').html();

So when you want to restore the list, you can do:

$('.list').html(original);

DEMO

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top