JSFiddle - React, Tailwind, and code Playground
HTML
<button id="asc"> sort by price asd</button><button id="desc"> sort by price desc</button>
<ul id="productList">
<div class="productContainer">
<li>
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcRD23fLxQXk26IPJjdq_iHhSg--9tzrRzI6aEAu-xrcgjxNZ83Q"></a>
<div class="productInfo">
<h4>
<!-- SORT ALL DIVS BASED ON A TAG CONTENT -->
<a class="productTitleForSorting" href="product-page-link">NAME</a><br>
</h4>
<div class="product-price">
<span id="lowestPrice">PRICE:
<!-- OR SORT ALL DIVS BY PRODUCT PRICE SPAN CONTENT -->
<span class="productPriceForSorting">h123</span></span>
</div>
</div>
</li>
</div>
<div class="productContainer">
<li>
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcRD23fLxQXk26IPJjdq_iHhSg--9tzrRzI6aEAu-xrcgjxNZ83Q"></a>
<div class="productInfo">
<h4>
<!-- SORT ALL DIVS BASED ON A TAG CONTENT -->
<a class="productTitleForSorting" href="product-page-link">NAME</a><br>
</h4>
<div class="product-price">
<span id="lowestPrice">PRICE:
<!-- OR SORT ALL DIVS BY PRODUCT PRICE SPAN CONTENT -->
<span class="productPriceForSorting">a321</span></span>
</div>
</div>
</li>
</div>
<div class="productContainer">
<li>
<img src="http://t0.gstatic.com/images?q=tbn:ANd9GcRD23fLxQXk26IPJjdq_iHhSg--9tzrRzI6aEAu-xrcgjxNZ83Q"></a>
<div class="productInfo">
<h4>
<!-- SORT ALL DIVS BASED ON A TAG CONTENT -->
<a class="productTitleForSorting"...
JavaScript
function sortByPrice(a,b){
return $(a).find('.productPriceForSorting').text() > $(b).find('.productPriceForSorting').text();
}
function sortByPriceDesc(a,b){
return $(a).find('.productPriceForSorting').text() < $(b).find('.productPriceForSorting').text();
}
function reorderEl(el){
var container = $('#productList');
container.html('');
el.each(function(){
$(this).appendTo(container);
});
}
$('#asc').click(function(){
reorderEl($('.productContainer').sort(sortByPrice));
});
$('#desc').click(function(){
reorderEl($('.productContainer').sort(sortByPriceDesc));
});