Sort HTML list with HTML content using JQuery

前端 未结 2 694
春和景丽
春和景丽 2021-01-15 14:01

Is it possible to sort the list bellow from the lower number to the bigger number, keeping each li content?

  • 39 <
2条回答
  •  生来不讨喜
    2021-01-15 14:45

    Your function should be like this.

    function numOrdDesc(a, b) {
        var aTxt = parseInt($(a)[0].innerText, 10);
        var bTxt = parseInt($(b)[0].innerText, 10);
        return (bTxt - aTxt);
    }
    

    DEMO

提交回复
热议问题