Drupal Behaviors –
- By admin
- 9 May, 2012
- Comments Off
I was new to Drupal Behaviors (Drupal 7) and spent the last couple of days trying to sort out an issue.
ISSUE : click events, were not ‘seeing’ new DOM elements changed through AJAX.
NON-DRUPAL WORLD: I would use live() delegate() or on() (depending on jQuery version) with document.load()
After much wrestling , I was able to get the delegate() function working with Drupal.behaviors:
Drupal.behaviors.mymod= {
attach: function (context, settings) {
$("div").delegate(".block.help-find-something .select-menu li", "click", function(){
Drupal.mymod.populatemyselect($(this).parents('.select-menu').find('select'));
});
}
}
And so I was able to stay ‘in Drupal’. I haven’t seen any other examples like this in my searching so wanted to share. If this violates some sacred Drupal rule, I appologize in advance and thanks for letting me know. Until then… maybe it will help someone else .

Copyright © 2013