JSFiddle - React, Tailwind, and code Playground

HTML

<div id="posts_div">
    <li class="post">post 3</li>
    <li class="post">post 2</li>
    <li class="post">post 1</li>
</div>

<button id="sort">Sort</button>

JavaScript

$("#sort").click(function() {
            var posts = $("#posts_div .post").get();
            posts.sort(function(a, b) {
               return ($(a).text()) > ($(b).text());
            });       
            $.each(posts, function(index, post) { $("#posts_div").append(post); });
    });