Reputation: 1629
I'm loading a custom block into a div using AJAX, this works well, now the problem is: the javascript (jquery) is not being attached to the block contents. It does work when I load the block the regular way. I know this has something to do with drupal attach behavior, but I'm doing it wrong. I've wrapped the jquery I want to use like this:
(function($) {
$(document).ready(function(){
// the code goes here
});
// code to make it work with drupal
jQuery('.ajax-processed').once().ajaxSuccess(function() {
Drupal.attachBehaviors();
});
})(jQuery);
Not sure where it's going wrong. Please tell me if you need more info in order to help me.
Thanks in advance
Upvotes: 3
Views: 4285
Reputation: 1629
Found the solution in the meanwhile, had to wrap the code in this:
( function ($) {
Drupal.behaviors.mymodule = {
attach: function(context,settings) {
//code goes here
}
};
})(jQuery);
Upvotes: 3