JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="sortPrice()">Sort by price Low -> High</button>
<button onclick="sortPopularity()">Sort by Popularity Low -> High</button>
<div id="list">
<div class="listing-item" data-price="4" data-popularity="4">[Red Socks] Price: $4 | Popularity: 3</div>
<div class="listing-item" data-price="2" data-popularity="2">[Blue Socks] Price: $2 | Popularity: 1</div>
<div class="listing-item" data-price="1" data-popularity="1">[Green Socks] Price: $1 | Popularity: 2</div>
<div class="listing-item" data-price="3" data-popularity="3">[Yellow Socks] Price: $3 | Popularity: 4</div>
</div>
JavaScript
var divList = $(".listing-item");
function sortPrice(){
divList.sort(function(a, b){ return $(a).data("price")-$(b).data("price")});
$("#list").html(divList);}
function sortPopularity(){
divList.sort(function(a, b){ return $(a).data("popularity")-$(b).data("popularity")});
$("#list").html(divList);}