How to know which jquery version was loaded

Asked

Viewed 3,632 times

7

The code below shows me perfectly if the jQuery was or was not loaded:

if (jQuery) {
    $('div#home_login').attr('style', 'background: green');
} else {
    $('div#home_login').attr('style', 'background: red'); }

However, how do I know which version was loaded, or versions, because I have some plugins that do not work with certain versions, such as autocomplete and the .on that do not work with the same version.

I wanted, when entering the page, to know which version or versions were loaded.

1 answer

4


Use the command $.fn.jquery to get a string with the version. Note in the example, that the version that will be loaded in the project will always be the last, will never be loaded more than one version at the same time.

var versaoJquery = $.fn.jquery;
console.log('Versão jQuery: ' + versaoJquery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>

Source: jQuery API

  • show, it worked cool, I just don’t know if it will display all versions loaded, hopefully.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.