Why jQuery does not execute when using the shorthand $-function?

Are you using the jQuery library? Are you trying to use its functions by using the “$” as the shortcut for “jQuery” and it does not work?

This means that somewhere in your javascript code the jQuery.noconflict() function is called. This function overrides the shorthand “$” notation and allows only for the use of “jQuery”. This is done as to avoid conflicts with other libraries that might be being used simultaneously and have the same shorthand notation. The popular WordPress platform, loads jQuery in the no conflict mode when using the build-in function wp_enque_script(‘jquery’) to load the library.

The option then is to use jQuery with the standard calling notation:

jQuery(document).ready(function(){ jQuery(“div”).hide(); });

Alternatively, your preferred new shorthand notation can be assigned:

var $jq = jQuery.noConflict();  $jq(document).ready(function(){ $jq(“div”).hide(); });

Finally if you still insist on using the shorthand “$” notation you can assign it for use only in the document ready are and avoid conflicts with other libraries:

jQuery.noConflict(); //Note “$” assigne at “function($)” jQuery(document).ready(function($){ $(“div”).hide(); });

Options are endless with jQuery…

Leave a Reply