Last updated August 1, 2015. Created on February 23, 2007.
Edited by Christopher James Francis Rodgers, Pere Orga, chrisjlee, LeeHunter. Log in to edit this page.

Drupal provides methods for implementing JavaScript. Using these methods will help to keep your code clean and to ensure compatibility with the way other modules implement JavaScript.

Beginners note aside: In Drupal 7, there are four primary methods of adding JavaScript to Drupal. See Managing JavaScript in Drupal 7. JavaScript code Should NOT be embedded in the HTML.

A couple of simple principles guide Drupal's JavaScript approach:

  • All pages should be perfectly functional without scripts. JavaScript provides alternatives or supplements - not replacements - for standard elements.
  • No JavaScript is hard-coded into pages. Rather, actions are attached dynamically to page elements--and only if the needed JavaScript support is present.

See also the JavaScript developer API in the API section of the handbook.

Note: this section is currently being overhauled. The numbered subsections are the new content added to date - more to come very soon! The non-numbered subsections are old content that needs to be incorporated, updated or removed.

See also:


Looking for support? Visit the forums, or join #drupal-support in IRC.