I read about Drupal behaviors today, and I tried writing the following code.
(function ($) {
Drupal.behaviors.mymodule = {
attach: function (context, settings) {
$('#mymodule_id', context).change(function () {
alert('Handler for .change() called.');
});
}
};
}(jQuery));
- Is
Drupal.behaviors.mymodule
the namespace? - What are the context and settings parameters passed to the Drupal behavior?
- Is this the equivalent of
document.ready()
? - Can I attach any number of functions?
- Can I define JavaScript functions which will be called somewhere?