A Plugin to help determine the version of jQuery.
Code:
function jQueryVersion() { var ver = (new jQuery()).jquery; // if there are two .'s it is a bug fix release if(ver.match(/\./g).length == 2) { return { "version" : ver, "major" : ver.substr(0, ver.indexOf(".")), "minor" : ver.substr(ver.indexOf(".") + 1, ver.lastIndexOf(".") - ver.indexOf(".") - 1), "revision" : ver.substr(ver.lastIndexOf(".") + 1) } } // otherwise it is an initial release else { return { "version" : ver, "major" : ver.substr(0, ver.indexOf(".")), "minor" : ver.substr(ver.indexOf(".") + 1), "revision" : 0 } } }
Usage example:
jQuery.fn.myplugin = function() { var version = jQueryVersion(); if(parseInt(version.minor) < 1) { alert("jQuery version 1.1 or higher is required for myplugin"); return this; } }