开发者

jQuery: What event gets triggered when a jQuery animation or ajax call is finished?

For example, i want to do know if $('#seomDiv').load(...); is completed in real time. I'm referring to the ajax .load() function.

Any idea?

EDIT: hmmmmm... I'm guessing something with setInterval()!

EDIT #2: I'm wondering if the completiong of the event can be somehow detected in real time from 开发者_如何学Ca totally seperate queue.

EDIT #3: I guess I have a better question: What event gets triggered when a jQuery animation or ajax is finished??


(Assuming you mean the Ajax .load() function)

Pass a callback to .load():

$('#someDiv').load("someurl.html", function(){
    alert('completed');
});

Documentation


jQuery .size() will tell you if an element exists, therefore has been loaded in the dom.

if ($('#seomDiv').size()){
 //code here
}

Non jQuery solution: You can also use javascripts native object property length:

if(document.getElementById("someDiv").length){
 //code here
}


The solution is to set a boolean from the .load() callback. An external function can check the value of the boolean in intervals. Check here for the details: How do you make an event listener that detects if a boolean variable becomes true?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜