Last updated July 26, 2017
Theming8.3.x

Anyone writing JavaScript for Drupal should use the Drupal.behaviors API when writing their custom JavaScript functionality. Doing so ensures that your JavaScript is executed at the appropriate times during the life cycle of a page, such as when the page loads, or after new DOM elements have been added via an AJAX request. In this tutorial we'll look at the problem that Drupal.behaviors solves and how to use Drupal.behaviors when writing your JavaScript code. By the end of this tutorial you should know how, and when, to use the Drupal.behaviors API in your projects.