Drupal: javascript not attached after ajax call (drupal typing behavior)

I am loading a custom block in a div using AJAX, this works well, now the problem is javascript (jquery) is not attached to the content of the block. It works when I load the block in the normal way. I know it has something to do with the drupal attach app, but I am doing it wrong. I 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); 

      

I don't know where this is happening. Please tell me if you need more information to help me.

Thank you in advance

+3


source to share


1 answer


Found a solution at the same time, had to wrap the code like this:



( function ($) {
    Drupal.behaviors.mymodule = {
        attach: function(context,settings) {

//code goes here

        }
  };
})(jQuery);

      

+2


source







All Articles