I have a div that shows the percentage of the particular color. I want to sort the div percentage in descending order. How to proceed? Below is my code
function displayLegend() {
for (var key in colorVariable1) {
let percentage = (countVariable1[key] / totalPCICount) * 100;
if(percentage) {
percentage = percentage.toFixed(2);
}
var line = document.createElement("div");
line.innerHTML = '<span class="box" style=" background: ' + colorVariable1[key] + ';"></span><span>' + key + '(' + percentage + '%)</span>';
document.getElementById("legendInfo").appendChild(line);
}
}
Below is the image.I want to sort the percentage part.