$ is not a function – jQuery

Once in a while, as a web developer working on a project that is based on a Drupal, you may come across this issue especially when utilizing the jQuery javascript library:

TypeError: $ is not a function

The simple solution is to create a wrapper so that Javascript is compatible with other libraries other than jQuery. As stated in the drupal.org website:

This wrapper is an anonymous closure that provides state throughout the page’s lifetime and ensures your code does not unintentionally create/override global variables.

It also explicitly imports the global jQuery variable so that your code can use the local $ variable instead of the jQuery global. This is essential because Drupal loads jQuery with noConflict() compatibility so the jQuery library does not setup the normal $ as a global variable.



  • http://drupal.stackexchange.com/questions/97061/getting-typeerror-is-not-a-function-with-or-without-jquery-update-install

March 13, 2015

Posted In: Information Technology

Tags: ,

Leave a Comment