0

$ is not a function is a common error message newbies encounter when trying to use JQuery in Drupal 7.

The explanation is that the usage of $ is disabled in Drupal to avoid conflicts with other libraries. But which other library is using $?

DOK
  • 31,943
  • 7
  • 59
  • 92
Jérôme Verstrynge
  • 55,046
  • 88
  • 271
  • 437
  • dupe: [What JavaScript libraries are known to use the global dollar sign: window.$?](http://stackoverflow.com/questions/4632041/what-javascript-libraries-are-known-to-use-the-global-dollar-sign-window) – cliffs of insanity May 13 '12 at 18:47

3 Answers3

4

At least two major ones:

It is probably because using one char for most commonly used function saves a lot of time. And due to some restrictions for characters in variable name in JavaScript there are actually two candidates for such one-char names: $ and _ (_ is used often for eg. gettext functions or throw-away variables). Thus I would rather expect that if some framework has some shortcut function with one char name, it is probably $.

Community
  • 1
  • 1
Tadeck
  • 125,377
  • 26
  • 148
  • 197
2

One of the common problems is several different versions of JQuery itself, though I'm not sure that is the reason in Drupal. Another possibility is Mootools

Nanne
  • 63,347
  • 16
  • 116
  • 159
  • Drupal says it is to avoid conflict between JS libraries themselves. – Jérôme Verstrynge May 13 '12 at 18:30
  • I meant that although it sounds like they mean different libraries, the same would be true for different versions of JQuery itself. So while a valid reason, I suspect that wasn't the primary goal in this case. – Nanne May 13 '12 at 18:32
1

zepto also uses $, and is a lightweight alternative to jQuery:

http://zeptojs.com/

In addition, it matches most of the jQuery API.

Christophe
  • 25,975
  • 25
  • 91
  • 136