JSFiddle - React, Tailwind, and code Playground

HTML

<ul class="foo-bar">
    <li>3</li>
    <li>2</li>
    <li>8</li>
    <li>1</li>
    <li>5</li>
    <li>1</li>
</ul>
<div id="output"></div>

JavaScript

var sorted = $("ul.foo-bar > li").sort(function (a, b) {
    // in this case, the a and b are LI elements
    // which means that we need to parse their contents into integers before comparing them
    return parseInt(a.innerHTML) - parseInt(b.innerHTML);
});

sorted.each(function () {
    $("#output").append($(this).text() + " ");
});