WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

jQuery - The noConflict() Method


What on the off chance that you wish to utilize different systems on your pages, while as yet utilizing jQuery?


jQuery and Other JavaScript Frameworks

As you definitely know; jQuery utilizes the $ sign as an alternate way for jQuery.

There are numerous other well known JavaScript structures like: Angular, Backbone, Coal, Knockout, and more.

What if other JavaScript structures additionally utilize the $ sign as a shortcut?

If two distinct structures are utilizing the equivalent easy route, one of them may stop working.

The jQuery group have just considered this, and executed the noConflict() method.


The jQuery noConflict() Method

The noConflict() technique discharges the hang on the $ easy route identifier, with the goal that different contents can utilize it.

You can obviously still use jQuery, just by composing the full name rather than the shortcut:

Example

$.noConflict();
jQuery(document).ready(function(){
    jQuery("button").click(function(){
        jQuery("p").text("jQuery is still working!");
    });
});
Try it yourself »

You can likewise make your possess alternate route all around effectively. The noConflict() strategy restores a reference to jQuery, that you can spare in a variable, for later use. Here is an example:

Example

var jq = $.noConflict();
jq(document).ready(function(){
    jq("button").click(function(){
        jq("p").text("jQuery is still working!");
    });
});
Try it yourself »

If you have a square of jQuery code which utilizes the $ alternate way and you don't need to transform it everything, you can pass the $ sign in as a parameter to the prepared strategy. This permits you to get to jQuery utilizing $, inside this capacity - outside of it, you should utilize "jQuery":

Example

$.noConflict();
jQuery(document).ready(function($){
    $("button").click(function(){
        $("p").text("jQuery is still working!");
    });
});
Try it yourself »

jQuery Misc Reference

For a total review of all jQuery Misc strategies, if you don't mind go to our jQuery Misc Reference.