I am creating a script in JS that will be called from external sites, but my code requires Jquery to work, specially 1.7 and 1.8 for UI, I found a way to check if jquery is installed and get the version:
$().jquery
But this will give me back a string with dots (1.6.1); is there already a function to check if the version installed is older than the one that I required?
I also need the same for the UI library, i found this but I am not very sure if it works properly, or maybe I don't know how o use it:
//Get version:
$.ui.version
//Comnpare version
var version_required = 1.7.1
version = $.ui ? $.ui.version || "pre "+version_required : 'not found';
Thanks
I am creating a script in JS that will be called from external sites, but my code requires Jquery to work, specially 1.7 and 1.8 for UI, I found a way to check if jquery is installed and get the version:
$().jquery
But this will give me back a string with dots (1.6.1); is there already a function to check if the version installed is older than the one that I required?
I also need the same for the UI library, i found this but I am not very sure if it works properly, or maybe I don't know how o use it:
//Get version:
$.ui.version
//Comnpare version
var version_required = 1.7.1
version = $.ui ? $.ui.version || "pre "+version_required : 'not found';
Thanks
Share Improve this question edited Apr 14, 2013 at 6:57 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Mar 29, 2012 at 22:22 Eduardo Ponce de LeonEduardo Ponce de Leon 9,69613 gold badges55 silver badges86 bronze badges1 Answer
Reset to default 17This might work for you:
if (typeof jQuery != 'undefined' && /[1-9]\.[7-9].[1-9]/.test($.fn.jquery)) {
// jQuery is loaded and is at least version 1.7.1
}
Likewise, it's almost the same for the UI:
if (typeof jQuery.ui != 'undefined' && /[1-9]\.[7-9].[1-9]/.test($.ui.version)) {
// jQuery UI is loaded and is at least version 1.7.1
}
First it checks to make sure jQuery is available and then it uses some simple regex pattern to test that the version numbers are within an acceptable range.
UPDATE: This will also work with jQuery 2 and 3.