How is jQuery checking if the document is loaded? How it is checking that the document load is finished?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Check out the function bindReady in the source code.
They bind to the DOMContentLoaded event (or onreadystatechange on some browsers). They also have a fallback to the regular load event, in case the DOMContentLoaded isn’t supported or not fired for other reasons. On browsers supporting it, they use this call:
On IE <9:
The second instance of
DOMContentLoadedin these calls is their own function – actually a reference to thereadyfunction right abovebindReadyin the source code. This function will check that the DOM tree is actually done by checking fordocument.body. If it doesn’t exist yet, they wait a millisecond (using setTimeout) and check again. When document.body exists, they traverse the list of callbacks you’ve set.