Hello Readers,
jquery.noConflict is the jquery function (jquery is the client side library) when we use the jquery.noConflict function in jquery it removes the conflict between different jquery libraries like Mootools, Prototype etc. they also use jquery $() as their global function. So, when we use different jquery libraries we have sometimes the problem create (conflict the jquery) to resolve this problem we use the jquery.noconflict function into the <script> jQuery.noConflict </script> tag after loaded the jquery libraries.
So,we use the jquery.noconflict function to tell the jquery that you want to remove anything declares from the global javascript namespace because you want to laod jquery again and reuse those names.
As, the developer know that basically the jquery use the $ sign as as shortcut. So, if different frameworks are using the same shortcut, sometimes might be stop working, because there are many other popular javscript framework like (Angular, Backbone, Ember, node and many more). jQuery team have already thought about this, and implemented the noConflict() method (to release the conflict).
The noConflict() method releases the hold on the ($) shortcut identifier, so that other scripts can use it.
First, use the ($) sign in case of noConflict function in jquery and writing jquey its full name instead of the shortcut.
Example 1:
$.noConflict();
jQuery(document).ready(function(){
jQuery("button").click(function(){
jQuery("p").text("jQuery is still working");
});
});
Example 2:
Using jq instead of $ and it also works fine.
var jq = $.noConflict();
jq(document).ready(function(){
jq("button").click(function(){
jq("p").text("jQuery is still working");
});
});
Exmaple 3:
In case, if you have a jquery code block which uses the $ shortcut you just pass the $ sign as a parameter to ready method.
$.noConflict();
jQuery(document).ready(function($){
$("button").click(function(){
$("p").text("jQuery is still working");
});
})
0 Comment(s)