jQuery: Document.ready vs windows.load

This entry is part 4 of 33 in the series jQuery Tutorial

The ready() event occurs after the HTML document has been loaded, while the load() event occurs later, when all content (e.g. images) also has been loaded.

The load() event is a standard event in the DOM, while the ready() event is specific to jQuery.

The purpose of the ready() event is that it should occur as early as possible after the document has loaded, so that code that adds funcionality to the elements in the page doesn’t have to wait for all content to load.

<!DOCTYPE html>
<html>
<head>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script>
        $(document).ready(function() {
            $('#doc').html('Document is ready and loaded');
        });

        $(window).load(function() {
            $('#win').html('Window is ready and loaded');
        });
    </script>
</head>
<body>
<h4 id='doc'>Document Not Ready</h4>
<iframe src="https://codecrawl.com"></iframe>
<h4 id='win'>Window Not Ready</h4>
</body>
</html>

Run the code above and you will find that document will get ready first.

As for window, it will be ready after codecrawl.com is loaded inside the frame.

Try The Code

jQuery: Introduction

This entry is part 1 of 33 in the series jQuery Tutorial

jQuery is a Javascript framework written in Javascript.

It is the most common libraries available for Javascript and it is the most popular Javascript library.

jQuery is easy to learn, there are other tools such as jQuery UI and jQuery Mobile that are built on top of it.

Other frameworks that are similar to jQuery are Prototype JS and Mootools.  Even Yahoo has its own set of library called the YUI.

jQuery is what make coding in Javascript fun and it is the first Javascript framework that we should learn.