What’s the best way of running a function depending on the version of jquery running?
Right now I have:
var jqVersion = jQuery().jquery;
if (jqVersion == '1.4.2') {
//jQuery 1.4.2 specific script here.
} else {
//jQuery that works on rest of the site here
}
This works fine in Firefox, but in Chrome and IE the page gives an error for the code in the else block even if the condition is met and the else is unneeded. Cheers.
If your error is associated with
.prop(), that was added in jQuery version 1.6 then you should just check to see if that method is available and act accordingly.or even just:
FYI, you can see what version any given jQuery feature was added here.
My recommendation is to check to see if the specific method you want is there as above. But, if you feel you have to check versions, then you need to check greater than, not for equality. As you already know,
jQuery().jQuerycontains the version as a string. If you want to check for a version greater than some number, then you need to parse that string into numbers and compare to them. Here’s a function to do that:Example usage: