Jquery onChange event for Div

I have a page with the following two divs:

<div id="searchResults">
</div>

<div class="postSearchOptions" style="display: none;">
</div>

      

Is there a way that I can make the "postSearchOptions" div where the "searchResults" div is updated on the AJAX call? I have no control over the AJAX calls and I want to detect any changes in the "searchResults" div.

I tried to write the following JQuery code, but then realized that it requires JQuery 1.4 and I only have 1.3:

$("#searchResults").live("change", function() {
    $(".postSearchOptions").css("display", "inline");
});

      

Is there a way to catch the search resolution change event using standard JavaScript or JQuery 1.3? Thanks!

+1


a source to share


4 answers


I don't think the onchange event will fire if you change innerHTML programmatically. Why don't you just show the search options by mail after receiving these changes, then why don't you include it as the last line in your ajax success method.



NTN

0


a source


If the AJAX calls are made with jQuery, you can call the global event handler ajaxComplete

and run your code there.



+1


a source


You can use setInterval to look, but as others have said it would be better to detect the change in the ajax callback. Here's a sketch of what the plugin will look like a "look" node, as you are trying to do with a live one:

jQuery.fn.watch = function() {
  this.each(function() {
    var original = $(this).html();
    setInterval(function() {
       var newHtml = $(this).html();
       if (newHtml != original) {
         $(this).trigger('change');
         original = newHtml;
       }

    }, 500);

  } );
}

      

0


a source


work, do ....

jQuery.fn.watch = function() {
      this.each(function() {
        var obj = $(this);
        var original = $(this).html();
        setInterval(function() {
           var newHtml = $(obj).html();
           if (newHtml != original) {   
            $(obj).trigger('change');
            original = newHtml;
           }

        }, 500);

       } );
}

      

-1


a source







All Articles