Jquery Ajax element.ready possible?
سؤال
I would like to catch some attributes in a content but this content is updated by Ajax. The issue is that my function trigger before the whole content is displayed, so I don't catch anything.
I want my function to wait for the end of the ajax function.
I thought, there was an option like :
$(element).ready(function() {
blablabla;
});
Thank you !
المحلول
Put your function in the success section of the $.ajax function? For example:
$.ajax({
url: "test.html",
context: document.body,
success: function(){
$(element).addClass("done");
yourFunction();
}
});
نصائح أخرى
You have access to the original DOM from within the success handler, so you can write a success handler that updates the original DOM, generates the new DOM elements however you want and then append them when you're ready so I don't see the point of this.
لا تنتمي إلى StackOverflow