What does $of document mean in JQuery

  • 2020-03-30 03:33:10
  • OfStack

JQuery has a handy little function for quickly loading javascript into the DOM. It's called ready... He executes before the page loads.

Why not use window.onload(), because when the window.onload function is executed, everything is loaded, including images, banners, and so on. Remember that larger images are slower to download, so the user has to wait for the large image to download before seeing the effect of the code executed by window.onload(), which takes a long time, which is not what we want.

But $(document).ready(fn): binds a function to execute when the DOM is loaded ready to query and manipulate.

This is one of the most important functions in the event module because it can greatly improve the responsiveness of web applications.

In short, this method is purely an alternative to registering events with the window.load event. Using this method, you can call the function you bind as soon as the DOM is loaded and ready to read and manipulate.

$(document) means, get the entire web document object (similar to window.document),

$(document).ready means when the document object is ready. The above code means that the document object is checked until it is allowed to be manipulated (this is faster than the window.onload() function, since the document object is loaded and the code can be executed without waiting for the image in the page to download) - this is what we want.


Related articles: