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

Where do we use jQuery.noConflict() method?

How can I use the jQuery.noConflict() method to avoid the conflicts between frameworks? Where do we use the jQuery.noConflict() method correctly in the code (which section)?  I have the following inside the script tags:

jQuery(document).ready(function(){\n    jQuery("button").click(function(){\n        jQuery("h3").text("jQuery works perfectly");\n    });\n});\n



1 Answer
Ricky Barnes

jQuery.conflict() method allows you to use multiple frameworks, while using jQuery. 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.

You can try to run the following code to learn how to work with the noConflict() method:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$.noConflict();
jQuery(document).ready(function(){
   jQuery("button").click(function(){
      jQuery("h3").text("jQuery works perfectly");
   });
});
</script>
</head>
<body>
<h1>Testing jQuery</h1>
<h3>Click below:</h3>
<button>Click me</button>

</body>
</html>

Live Demo

Advertisements

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