The jQuery function allows to attach one or more handlers that will be executed as soon as the page's Document Object Model (DOM) becomes safe to manipulate. Aloso you can use the ready() method of jQuery object.
Most browsers provide similar functionality in the form of the DOMContentLoaded event. However, the DOMContentLoaded event handler added after the event is fired is never executed. But a handler added using the jQuery will be executed.
Below are examples of how to add a handler for the document load event.
$(handler); // recommended $(document).ready(handler); $("document").ready(handler); $("img").ready(handler); $().ready(handler);
Browsers also provide the load event on the window object. When this event fires it indicates that all assets on the page have loaded, including images. This event can be observed in a common jQuery way $(window).on("load", handler). In cases where code relies on loaded assets such image size, the code should be placed in the load event handler.