Minggu, 05 Juni 2011

window.onload = function(){} VS $(document).ready (function(){}

$(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(){});

Tidak ada komentar:

Posting Komentar