HiveBrain v1.2.0
Get Started
← Back to all entries
principlejavascriptCritical

window.onload vs $(document).ready()

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
readyonloadwindowdocument

Problem

What are the differences between JavaScript's window.onload and jQuery's $(document).ready() method?

Solution

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

The onload 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 functionality to the elements in the page doesn't have to wait for all content to load.

Context

Stack Overflow Q#3698200, score: 1373

Revisions (0)

No revisions yet.