Warning message

Documentation is currently being migrated into the new system. Some pages might be temporarily missing, and some guides might appear empty. Thank you for your patience while we are improving Drupal.org documentation.

JavaScript API

This guide describes the APIs in Drupal dealing with JavaScript, AJAX, and AHAH.

    JavaScript API overview

    This page is a description of how JavaScript is implemented in Drupal 7, including an in-depth look at the drupal.js file.

    Ajax Forms in Drupal 7

    Introduction to Ajax-enabled Forms

    Managing JavaScript in Drupal 7

    Drupal 7 has introduced several new techniques that allow you far greater flexibility and control in the scripts you can have on your Drupal

    Adding JavaScript to your theme or module

    The Drupal API function drupal_add_js() lets you add a JavaScript file, setting or inline code to the page and it takes 5 parameters (see

    Debugging JavaScript

    If you don't have an IDE that can debug JavaScript for you, then one alternative is the Firefox add-on called Firebug.

    Introducing jQuery

    jQuery is a cross-browser JavaScript library, which means it provides some pre-defined functions to make your life easier.

    Ajax in Drupal using jQuery

    Ajax is a type of functionality that enables your pages to retrieve information from a resource on the server without the need to reload.

    Version compatibilities between jQuery and core

    Now that jQuery ships within the Drupal core framework (as of D5), this page outlines and cross-references the most current versions of

    Multiple different versions of jQuery co-existing


    Creating custom Drupal.ajax object 'on the fly' and attach it to any DOM element on the page (div, td, span etc.)

    Add AJAX capability to a new DOM element

    Add More Button for Text field /file field using AHAH with drupal 7 form API

    Example Code snippet to create ADD MORE BUTTON with drupal 7 form API

    Simple Drupal AJAX load with jQuery and delivery callback

    Simple Drupal AJAX load with jQuery and delivery callback

    The JavaScript Language

    The JavaScript language is easy to understand for those already familiar with PHP.

    JavaScript and the DOM

    The Document Object Model (DOM) is an API for HTML and XML documents. It provides a structural representation of the document.