As we know that jQuery uses the $ sign as a shortcut and what will happen if other JavaScript frameworks use the same shortcut.
In that scenario, it giving error “$ is not a function” due to conflication with other libraries.
To avoid the conflicts with other libraries you can remore $ sign with jQuery but its very difficult to remove from everywhere so you can fix this error by using the jQuery noConflict()
method.
You can also define your own shortcut because noConflict()
method returns a reference to jQuery which you can hold in your custom variable.
- $.noConflict();
- jQuery(document).ready(function(){
- jQuery("a").click(function(){
- jQuery("p").text("Its working!");
- });
- });
Here i create $jq alias to jQuery function.
- var $jq = jQuery.noConflict();
- $jq(document).ready(function() {
- $jq( "div" ).text('Welcome to ExpertPHP');
- });
- jQuery(function($){
- // Your can write here your jQuery code by using the $
- });