Check if the HTML document ready in JavaScript

Description

The following code shows how to check if the HTML document ready.

Example


<!--  w  w w.j a v  a2  s .c  o  m-->

<!DOCTYPE HTML>
<html>
<head>
<script>
document.onreadystatechange = function() {
if (document.readyState == "interactive") {
document.writeln("interactive");
}
if (document.readyState == "loading") {
document.writeln("loading");
}
if (document.readyState == "complete") {
document.writeln("complete");
}

}
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Check if the HTML document ready in JavaScript
Home »
  Javascript Tutorial »
    Document »
      Event
Javascript Tutorial Event
Change element style with document on click...
Check if the HTML document ready in JavaScr...