Drupal jQuery Behaviors

(function($) {
  Drupal.behaviors.mymodulename = {
   attach: function (context, settings) {
     // Code here
   }
  };
} (jQuery));

Store our function as a property of Drupal.behaviors

context: Initially the context will contain the entire document and after AJAX call will have newly added elements.

settings: The use of settings is to pass values from PHP to Javascript.

Tags