views:

317

answers:

5

When writing a new jQuery plugin is there a straightforward way of checking that the current version of jQuery is above a certain number? Displaying a warning or logging an error otherwise.

It would be nice to do something like:

jQuery.version >= 1.2.6

in some form or another.

+3  A: 

Try this:

>>> jQuery.fn.jquery;
"1.3.2"
Paolo Bergantino
A: 
$().jquery;

or

jQuery.fn.jquery;
rahul
A: 

Found this in jquery.1.3.2 source:

 jQuery.fn = jQuery.prototype = {
    init: function( selector, context ) {
    .....
    // The current version of jQuery being used
    jquery: "1.3.2",

I didn't check, but something like "$.fn.jQuery" might work.

Arnis L.
+6  A: 

Here is a check I used to make sure the user was using at least v. 1.3.2 of jQuery.

if (/1\.(0|1|2|3)\.(0|1)/.test($.fn.jquery) 
                    || /^1.1/.test($.fn.jquery) 
                    || /^1.2/.test($.fn.jquery)) 
{
    //Tell user they need to upgrade.
}
RedWolves
Thanks to everyone who left answers, I guess there's no easy way to check it because of it being a String, I think the above solution is the most appropriate though. Cheers
roguepixel
+1  A: 

See my answer here: jQuery Version Compatibility Detection

kflorence
@kflorence nice work
roguepixel