From the jQuery API documentation ...
.ready ()
Description: Indicate the function to execute when the DOM is fully loaded. Although JavaScript provides a load event to execute code when a page is displayed, this event does not fire until all assets, such as images, have been fully received. In most cases, a script can be executed as soon as the DOM hierarchy has been completely built .
Learn more about jQuery Ready
DOM definition, from W3C ...
What is a document object model?
The document object model is a platform and language interface that will allow programs and scripts for dynamic access and update the content, structure and style of documents.
Defining .load () from jQuery API documentation
.load ()
Description: Bind an event handler to a JavaScript load event.
Example: Run the function when the page is fully loaded , including graphics.
$ (window) .load (function () {
});
After studying this and much contemplation, I came to the conclusion that the wording of the question is incorrect, given their three options. Of course, based on this line of thinking, since there is no right answer to the quiz question, my original answer was also wrong.
Original W3Schools jQuery Quiz question:
What jQuery function is used to prevent code from being run until the document has finished loading?
Now we analyze the initial three answers:
but. $ (Document) .load ()
This was my initial answer, but after posting this question to StackOverflow I realized that $ (document) .load () is not valid code, as far as I can tell. $ (window) .load () is what I originally meant. Using $ (window) .load (), you will prevent code from executing before the entire window loads, including all its elements, images, etc.
A may not be the right answer because the wording is "document.load", although it should be "window.load".
B. $ (Document) .ready ()
This is the official answer and valid jQuery code. It starts when the DOM is ready, but before anything else finishes loading. I would say that you cannot say that the “document” completed the download, otherwise the word “document” and “DOM” will have the same meaning and be used interchangeably.
B cannot be the right answer, because without images and other assets the page (document) did not finish loading.
C. $ (Body) .onload ()
C cannot be the right answer simply because "onload ()" is not part of the jQuery library.
Conclusions):
How the question is formulated: “What jQuery function is used to prevent code from running before the document finishes loading?”, There is no correct answer from the three presented. $ (window) .load () should be the right answer as it refers to the "page" or "document" as a whole, and not just the DOM.
To accept the official answer "$ (document) .ready ()", the original question should be rewritten as follows: "What jQuery function is used to prevent code from running before the DOM is finished loading?"