function sort(type, order) { let jsList = document.querySelector("#jsList"); // console.log(jsList) let obj = { id: 0, price: 1, sales: 2, }; if (order === "asc") { let arr = Array.from(jsList.children).sort((a, b) => { return ( a.children[obj[type]].innerText - b.children[obj[type]].innerText ); }); jsList.innerHTML = ""; arr.forEach((item) => { jsList.appendChild(item); }); } if (order === "desc") { let arr = Array.from(jsList.children).sort((a, b) => { return ( b.children[obj[type]].innerText - a.children[obj[type]].innerText ); }); jsList.innerHTML = ""; arr.forEach((item) => { jsList.appendChild(item); }); } }