I've got two different modules which in many ways work together. One of the things they work together on is that module A loads content via AJAX, and module B needs to attach event listeners to the content loaded.
However, it appears that when content is loaded via AJAX by module A, only the 'attach' function of Drupal.behaviours.a gets invoked, and not the 'attach' function of Drupal.behaviours.b. Both functions gets invoked on page load, but not on subsequent AJAX content loading.
// This runs every time module A loads new content.
Drupal.behaviors.a = {
attach: function(context, settings) {
alert('a:attach');
}
}
// This only runs on page load, but never when module A loads new content.
Drupal.behaviors.b = {
attach: function(context, settings) {
alert('b:attach');
}
}
How do i make the 'attach' function of Drupal.behaviours.b run every time any module loads new content?
Drupal.attachBehaviors();
to the ajax success callback?$('body').ajaxSuccess(Drupal.attachBehaviors);
will probably work