window.onload- Code in this method get executed when DOM tree is ready. But fact is code in this method executed when DOM tree is ready and All the external resource are load like Images, Flash vidoe or quicktime video. Loading of the external resources deplay execution of the actual script when page get displayed. $(document).redy- Code in this method get executed once DOM tree loading is done. That means its not wait for the external resource get loaded. And run the javascript code which is in function.