$(document).ready(function(){
   //your code here
});

$(function(){
   //your code here
});

To wait until the page is finish loaded before execute particular code, you can use any one of jquery codes above. The both codes above are 99% the same. They are just make sure the codes of the pages are finish loaded, but they can't make sure the images on the pages are finish loaded. To detect images, you need to use the codes below :
window.onload = function(){
   //your code here
};

$(window).load(function(){
   //your code here
});

The 1st code above window.onload is normal javascript which is bad idea because it prevents you from setting onload from anything else or will erase any other "onload". To avoid overwriting the hooks that are already attached to the window.onload, attach your function with jQuery: $(window).load(function(){});


Posted by Zac1987 on 05 June, 2011

1 Comment

  1. Anonymous Said,

    Thanks for finally talking about > "window.onload = function() VS $(document).ready (function()" < Loved it!

    My weblog: Testo XL muscle

    Posted on 10:36 PM, November 30, 2014

     







Enter your email address:

Subscribe in a reader

Follow zac1987 on Twitter

Chatting Box

Donation

If you feel my website is informative and it is useful for you, please donate some money to support me or buy me a drink. I will continues this good works. Thank you.