Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to use multiple versions of jQuery on the same page?

Can we add multiple versions of jQuery on the same web page? Will it be possible to work with them separately without conflicts?

I want to include the following two versions of jQuery and want t work with them separately:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>\n<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

Is it possible to work with them separately without conflicts?


1 Answer
Amit D

Yes, you can use multiple versions of jQuery on the same page. To avoid any kind of conflict, use the jQuery.noConflict() method. jQuery.noConflict() method allows you to use multiple frameworks, while using jQuery. Other JavaScript frameworks include Ember, Angular, Backbone, etc.

The $ sign is used for jQuery, but what if other frameworks also use the same $ sign; this may create issues and conflict. To avoid this, jQuery issued the noConflict() method. The method releases the $ sign to be used my other JavaScript frameworks. Use jQuery with the name, jQuery.

With this, you can also use multiple versions of jQuery on the same page. You can try to run the following code to learn how to use multiple versions of jQuery on the same web page:

<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
   var $x = jQuery.noConflict();
   alert("Version: "+$x.fn.jquery);
</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script>
   var $y = jQuery.noConflict();
   alert("Version: "+$y.fn.jquery);
</script>
</head>

<body>
</body>
</html>

Live Demo

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.