var ul=$("#test-div ul"); var arr=[]; ["Pascal","Lua","Ruby"].forEach(x=>{ul.append('<li><span>' +x+ '</span></li>')}); var texts=ul.find("span").map(function(){ return $(this).text(); }).get(); texts.sort(); ul.find('span').each(function(index){ $(this).text(texts[index]); });
Sign in to make a reply
4zhuma
var ul=$("#test-div ul"); var arr=[]; ["Pascal","Lua","Ruby"].forEach(x=>{ul.append('<li><span>' +x+ '</span></li>')}); var texts=ul.find("span").map(function(){ return $(this).text(); }).get(); texts.sort(); ul.find('span').each(function(index){ $(this).text(texts[index]); });