$(document).ready()
jQuery document.ready will execute our code when the HTML is all ready, but before images and other resources have finished.
$(document).ready(function(){
//write your code here;
})
window.onload()
window.onload() runs after everything has finished loading including images and scripts, but usually not stylesheets. Use this for code when page wouldn't change anymore.
window.onload = function() {
init();
doSomethingElse();
};
Hopefully this will help you. Thanks.