I have several products. Each has a specific price and I want a button to sort them by the price.
The products are like this on my site:
<div class="product" id="pr_1">Some Content</div>
<div class="product" id="pr_2">Some Content</div>
<div class="product" id="pr_3">Some Content</div>
...
I parsed the prices from PHP to JavaScript so I have an JavaScript Object containing all prices and product ids:
{12:1, 20:2, 7:3}
Currently the key is the price and the value is the product's id.
I want to have them reordered without reload. So JavaScript / jQuery only. I prefer plain JavaScript.
Is there any way to change the order of the div
s according to the prices of the products?