O'Reilly logo

Drupal 7 Module Development by Ken Rickard, John Wilkins, Larry Garfield, Matt Butcher, Greg Dunlap, Matt Farina

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding JavaScript

Most of the JavaScript written for Drupal utilizes jQuery but it is not a requirement. When JavaScript is added to the page there are some things to be aware of.

Drupal sets jQuery up to use its no conflict mode. This means that the $ variable is relinquished so Drupal can work with other JavaScript libraries that may use the $ variable. More detail is available at http://api.jquery.com/jQuery.noConflict.

In the absence of $ there are two methods for writing JavaScript that use jQuery. The first is to use jQuery in any place where you may have used the $. For example:

jQuery().ready(function() {
...
});

The other way is to wrap your code in an anonymous function and choose an alias. For example:

(function($) { $().ready(function() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required