Reputation: 1630
I've one function for sort div by price ASC and DESC. But it doesn't work on Safari. It's ok on Firefox/Chrome.
What's the reason?
The code (and a fiddle version):
function sortByPrice(a,b){
return $(a).find('.cicerone_price').text() > $(b).find('.cicerone_price').text();
}
function sortByPriceDesc(a,b){
return $(a).find('.cicerone_price').text() < $(b).find('.cicerone_price').text();
}
function reorderEl(el){
var container = $('#tabs');
container.html('');
el.each(function(){
$(this).appendTo(container);
});
}
$('#filter_price').change(function(){
if ($("#filter_price option:selected").val()=='desc'){
reorderEl($('.global_product').sort(sortByPriceDesc));
} else if ($("#filter_price option:selected").val()=='asc'){
reorderEl($('.global_product').sort(sortByPrice));
}
});
Upvotes: 3
Views: 1452
Reputation: 1630
The problem has been solved, for the solution, i add parseFloat for decimal
solution is here : fiddle correction
function sortByPrice(a,b){
return parseFloat($(a).find('.productPriceForSorting').text()) > parseFloat($(b).find('.productPriceForSorting').text()) ? 1 : -1;
}
Upvotes: 2