JQuery ajaxStart & ajaxComplete live?

I have the following works that work perfectly:

$(".new_comment").ajaxStart(function() { ajaxBanner('show'); // Disable button $("input[type=submit]", this).attr("disabled", true); }); $(".new_comment").ajaxComplete(function() { ajaxBanner('hide'); // Re-enable button $("input[type=submit]", this).removeAttr("disabled"); }); 

The only problem is that the page is displayed with a comment form. In many cases, the comment form is dynamically entered into the page, and this is not executed.

How can I do the above live ()?

thanks

+4
source share
2 answers

This has not been tested, but might be worth a try?

 $(".new_comment").live("ajaxComplete", function() { ajaxBanner('show'); // Disable button $("input[type=submit]", this).attr("disabled", true); }); 

An alternative is to add an event when you dynamically insert a comment form, but we need some more of your code for this (that is, where the injection takes place).

+1
source

I'm not sure exactly how .ajaxComplete() works when binding to a jQuery selection, but I believe that you could easily solve your problem by linking to an existing element, i.e. document , and then using regular selectors:

 $(document).ajaxStart(function() { ajaxBanner('show'); // Disable button $(".new_comment input[type=submit]").attr("disabled", true); }).ajaxComplete(function() { ajaxBanner('hide'); // Re-enable button $(".new_comment input[type=submit]").removeAttr("disabled"); }); 
0
source

All Articles