-3

What is the difference between

$(document).ready(function(){});

AND

$(window).load(function(){});
j08691
  • 204,283
  • 31
  • 260
  • 272
SNEH PANDYA
  • 797
  • 7
  • 22
  • 1
    Did you even search for this at all before posting? – xdumaine Apr 02 '14 at 15:37
  • Please take some time to search for an existing post in the future before posting a new one. As you can see there are numerous possible duplicates. – Lix Apr 02 '14 at 15:37
  • Simple terms, Document fires when the document is ready or (DOM). And window `.load` fires when the window is ready. In chrome for example, you can't get correct css dimensions using jQuery methods such as `.width()` or `.height()` until the window is ready. – khollenbeck Apr 02 '14 at 15:38
  • There is no difference, both have absolutely no effect, binding empty handler... – A. Wolff Apr 02 '14 at 15:41
  • 1
    @Lix Stackoverflow need to make question duplicates more noticeable to posters. Probably bigger and highlighted with colors. Maybe add an arrow or two. – NoName Aug 15 '20 at 16:14
  • @NoName - You may have a point there... Also I don't remember if the duplicate suggestions looked the same 5 years ago when this post was made :) – Lix Aug 16 '20 at 09:53

1 Answers1

1

From the docs:

Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside $( window ).load(function() { ... }) will run once the entire page (images or iframes), not just the DOM, is ready.

Felix
  • 37,892
  • 8
  • 43
  • 55