How to check what version of jQuery is loaded?
My goto means to determine the version:
$.fn.jquery
Another similar option:
$().jQuery
If there is concern that there may be multiple implementations of $
— making $.
ambiguous — then use jQuery
instead:
jQuery.fn.jquery
Recently I have had issues using $.fn.jquery
and $().jQuery
on a few sites so I wanted to note a third simple command to pull the jQuery version.
If you get back a version number — usually as a string — then jQuery is loaded and that is what version you're working with. If not loaded then you should get back
undefined
or maybe even an error.
Pretty old question and I've seen a few people that have already mentioned my answer in comments. However, I find that sometimes great answers that are left as comments can go unnoticed; especially when there are a lot of comments to an answer you may find yourself digging through piles of them looking for a gem. Hopefully this helps someone out!
You can just check if the jQuery
object exists:
if( typeof jQuery !== 'undefined' ) ... // jQuery loaded
jQuery().jquery
has the version number.
As for the prefix, jQuery
should always work. If you want to use $
you can wrap your code to a function and pass jQuery
to it as the parameter:
(function( $ ) {
$( '.class' ).doSomething(); // works always
})( jQuery )
…just because this method hasn't been mentioned so far - open the console and type:
$ === jQuery
As @Juhana mentioned above $().jquery
will return the version number.
if (typeof jQuery != 'undefined') {
// jQuery is loaded => print the version
alert(jQuery.fn.jquery);
}