Here the code is only sorting the li items in ascending order.How to sort in both ascending and descending order by using this code Sorting <li> tags
function sort(list, key) {
$($(list).get().reverse()).each(function (outer) {
var sorting = this;
$($(list).get().reverse()).each(function (inner) {
if ($(key, this).text().localeCompare($(key, sorting).text()) > 0) {
this.parentNode.insertBefore(sorting.parentNode.removeChild(sorting), this);
}
});
});
}
and
window.onload = function () {
var desc = false;
document.getElementById("stCodeDSC").onclick = function () {
// sortUnorderedList("list3", desc);
sort('ul.conn1>li', 'td.code1');
desc = !desc;
return false;
}
Any suggestion?
EDIT: If i give <0 then it is sorting in descending order..
EDIT2:
$(document).ready(function() {
var desc = false;
document.getElementById("stCodeDSC").onclick = function () {
// sortUnorderedList("list3", desc);
sort('ul.conn>li', 'td.code');
desc = !desc;
return false;
}
document.getElementById("stNameDSC").onclick = function () {
// sortUnorderedList("list3", desc);
sort('ul.conn>li', 'td.name');
desc = !desc;
return false;
}
});
window.onload.onclickor any of the other "native"onXYZevent handlers. I suggest you spend a little time reading about jQuery, because that's not how it is supposed to be used.