Reputation: 19443
I know that jQuery.fn.jquery
gives me 1.10.2
, and I want to use .on
binding for anything at least jQuery version 1.7
.
What I'm doing is:
var jQueryFloat = parseFloat(jQuery.fn.jquery); // 1.1
if (jQueryFloat >= 1.7) {
// do jQuery 1.7 and above specific code
}
1.1 is less than 1.7, so my jQuery 1.7 and above code does not get run.
Any ideas on another way to figure out if my current version of jQuery is greater than or equal to 1.7
? Thanks.
Upvotes: 2
Views: 2179
Reputation: 55792
If you are just looking to use .on()
if possible, then don't try and parse the version - use feature detection.
var iCanUseOn = !!$.fn.on;
if(iCanUseOn) {
} else {
}
If you want to use more than just .on()
, then that's fine, too. Come up with flags for each feature you want to use, but parsing the version is not a good way to solve this problem.
Upvotes: 12
Reputation: 15112
Use as below.
var arr = $.fn.jquery.split('.'); //["1", "10", "2"]
if(arr[0] > 1 || (arr[0] == 1 && arr[1] > 7))
{
//Do your thing
}
The above condition will work for future versions like 2.0.1 etc.
Upvotes: 6