/ javascript

window.onload, document.onload vs document.ready window.load

This test will clear the confusion about which event callback gets fired first.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>onLoad Test</title>
  <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
  <script>
  $(window).load(function () {
    console.log('$window.load - 4th');
  });
  $(function () {
    console.log('document.ready - 3rd');
  });
  window.onLoad = function () {
    console.log('window.onLoad - 1st');
  }();
  document.onLoad = function () {
    console.log('document.onLoad -2nd');
  }();
  </script>
</head>
<body>
  Check console.
</body>
</html>

I'll probably update the sciene behind it at a later stage.

window.onload, document.onload vs document.ready window.load
Share this