Search code examples
javascriptjquerydrupaljquery-events

In JavaScript or with jQuery is there an event that will be triggered when the contents of a div change?


Possible Duplicate:
Detect element content changes with jQuery

I am trying to modify the selected option in a select that appears in a module window after a file is uploaded. I have yet to find a way to hook into the end of this ajax callback. So I am wondering if there is a way to monitor the parent div for content changes and then activate it on that.

I don't think this is possible, but I wanted to see if anyone else knew better than me.

I am using Drupal 6 and jQuery 1.3 on this site with a lot of modules.


Solution

  • DOMSubtreeModified. But they are deprecated.

    For your case, it's better to intercept the AJAX request. This can be done in this way, without side effects:

    (function($) {
        var $ajax = $.ajax;
        $.ajax = function(url, settings) {
            // Detect something, See http://api.jquery.com/jQuery.ajax/
            // If settings does not exist, then settings = url
    
            $ajax.call(this, url, settings); // Call normal AJAX thing
        };
    })(jQuery);
    

    Instead of intercepting all AJAX requests, you can also add an ajaxComplete event.