$ 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
Please follow and like us:

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

March 13, 2015

Posted In: Information Technology

Tags: ,

Leave a Comment