Reputation: 735
I would like to add a loading image to my page. I have added my loading image at the beginning of my body tag, and I have removed loading image at the end of HTML tag. Now I am able to identify, when, Js files are completely downloaded. But, how to make sure that all elements in the page have been completely rendered? Now, I am using setTimeOut
function to add extra one second delay. Is there a way to identify, all elements in the HTML page have been rendered?
Upvotes: 0
Views: 198
Reputation: 168
document.onreadystatechange = function () {
if (document.readyState === "complete") {
//do everything here
}
}
The readyState property is used to determine the state of the document. Refer MDN docs : https://developer.mozilla.org/en-US/docs/Web/API/Document/readyState
Upvotes: 1