Categories
JavaScript Answers

How to detect if document has loaded with JavaScript?

Spread the love

Sometimes, we want to detect if document has loaded with JavaScript.

In this article, we’ll look at how to detect if document has loaded with JavaScript.

How to detect if document has loaded with JavaScript?

To detect if document has loaded with JavaScript, we can check if document.readystate is set to 'complete'.

For instance, we write

if (document.readyState === "complete") {
  init();
}

to check if document.readystate is 'complete'.

If it is, then document has loaded.

Conclusion

To detect if document has loaded with JavaScript, we can check if document.readystate is set to 'complete'.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *