I'm trying to execute a jquery function inside an IF statement.
basically, I am getting the value of a select option and if the value of selected option is what I want (htl in this example) then I want to execute the function!
but when I wrap the code within an IF statement, i get syntax error which I have no idea what's causing that issue.
This is my entire code:
var ascending = false;
$('.page_navigation .sortBy').change(function () {
var vals = $(this).val();
if (vals == "htl") {
///// I need to put the code bellow here
}
var sorted = $('.mypro').sort(function (a, b) {
return (ascending == (convertToNumber($(a).find('.prod-price').html()) <
convertToNumber($(b).find('.prod-price').html()))) ? 1 : -1;
});
ascending = ascending ? false : true;
$('#myCont').html(sorted);
});
var convertToNumber = function (value) {
return parseFloat(value.replace('£', ''));
}
could someone please advise on this issue?
I tried this and I get the syntax error:
var ascending = false;
$('.page_navigation .sortBy').change(function(){
var vals = $(this).val();
if(vals == "htl") {
var sorted = $('.mypro').sort(function(a,b){
return (ascending ==
(convertToNumber($(a).find('.prod-price').html()) <
convertToNumber($(b).find('.prod-price').html()))) ? 1 : -1;
});
ascending = ascending ? false : true;
$('#myCont').html(sorted);
});
var convertToNumber = function(value){
return parseFloat(value.replace('£',''));
}
}

}to close theifMove the}at the most bottom after$('#myCont').html(sorted);