Friday 25 May 2012

Force Drupal to attach Drupal behavior to new ajaxed content

Drupal.behaviors.my_ajax = function (context) {
    $('#content-group-inner a').live('click', function (e) {

        $('#content-group-inner a').addClass('my_ajax-processed');
        var url = $(this).attr('href');
        $('#content-region-inner').empty().html('<img src="ajax-loader.gif" style="margin-left:50%;"/>');        
        $('#content-region-inner').load(url,'ajax=1',function() {
                        Drupal.attachBehaviors('#content-region-inner');
                        });
        return false;
        });
   };

just change   $('selector').onvent(function (){}); 
=> $('selector').live('onvent', function (e){});

1 comment:

  1. Just using your code in to my demo site. and it's work perfectly fine. i think people should go through it.Thank you for sharing.

    Drupal Web Development

    ReplyDelete