0

I have seen lot's of discussion about the differences between

$(window).load();

and

$(document).ready();

but these are two variables in the same problem set. I became curious about

$(document).load();

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            console.log("Ready");
        })
    </script>
</head>
<body>
    <h1>THIS IS THE PAGE</h1>
    <img src="http://www.kayfabenews.com/wp-content/uploads/2012/07/nickelback.jpg">
    <script type="text/javascript">
        $(document).load(function(){
            console.log("Loaded");
        })
    </script>
</body>
</html>

There are no errors in the console and "Loaded" never prints out. I think I expected it to execute, in this case, exactly like document.ready. Why does this not complete? What am I missing about the document object or the load function?

EDIT: I don't see this as a duplicate as I am specifically NOT asking about the difference between $(window).load() and $(document).ready().... but why $(document).load() is not acting like $(document).ready().

notthehoff
  • 1,172
  • 1
  • 12
  • 28
  • 4
    http://stackoverflow.com/questions/8396407/jquery-what-are-differences-between-document-ready-and-window-load – Haych Nov 29 '15 at 18:06
  • 4
    The `.load()` function (in this case) just sets up a handler for the "load" event. Your code doesn't run because the "load" event is not fired on the `document` object. – Pointy Nov 29 '15 at 18:06
  • As the first one is [deprecated](http://api.jquery.com/load-event/), the choice should be easy – adeneo Nov 29 '15 at 18:06
  • Sort of a fair answer, @adeneo, but the same outcome exists using .on("load",function(){}) – notthehoff Nov 29 '15 at 18:38
  • @Pointy, your answer is what I was looking for. Thank you! – notthehoff Nov 29 '15 at 18:44

0 Answers0