开发者

Question about when the handler in $(document).ready(handler) gets called

I know that the $(document).ready(handler) executes the handler when the DOM structure is loaded. But if you have a script that executes after you click a link and the script contains a $(document).ready(handler), will the handler get called? (like does the handler get called as long as the document is ready even if the document had completely loaded a long time a开发者_如何学Cgo? Also if you have jQuery that edits a DOM structure, does any handlers for any existing $(document).ready run again since the DOM structure will change and be ready again?

Thanks!


Yes, the handler will get called if the document is already ready. No, it doesn't get called again for changes in the DOM.


Handlers bound with jQuery.ready() will fire even if they are attached after the initial ready event is fired. However, handlers bound with jQuery.bind("ready") will not. Potentially useful if you know, but could otherwise be confusing behaviour.

The events will not fire again when the DOM is manipulated.


It sounds like you're still getting the feel of jquery's execution. I would recommend popping some alert() calls in the different handlers during testing to get the hang of it. Like...

alert("This is first handler running.");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜