I'm writing my own Drupal 7 module, and like to use JQuery in it.
$('#field').toggle();
But I'm getting this error:
TypeError: Property '$' of object [object DOMWindow] is not a function
It seems that JQuery is not loaded. Otherwise $ should be defined.
Though I actually include it in the header:
<script type="text/javascript" src="http://rockfinder.de/misc/jquery.js?v=1.4.4"></script>
Do I have to do anything else to activate JQuery in Drupal? Is $ being overwritten by Drupal?
That's the website: http://rockfinder.orgapage.de
You can create the separate file for js and than add js file using the following:
According to Firebug, your jQuery file is being loaded:
But the
$
is being overwritten by something else:What you should do is encapsulate the use of the
$
variable with a function that invokes itself using thejQuery
object as it's first actual argument:"$ is not a function" is a very common error that you may face while working with jQuery. You can try any answers of given below:
OR
Basically this will allow our code to run and use the $ shortcut for JQuery.
From the Drupal 7 upgrade guide:
You can also just use the 'jQuery' variable instead of the $ variable in your code.
Chances are your script is not initialized this way, you'll have to use Drupal.behaviors.YOURTHEMENAME