top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Difference between $(document).ready() vs window.onload()?

0 votes
649 views
What is Difference between $(document).ready() vs window.onload()?
posted Jan 17, 2018 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

$(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.

answer Feb 24, 2018 by Vishi Gulati
...