Home > Web Front-end > JS Tutorial > What does $(document) mean and what does it do in JQuery_jquery

What does $(document) mean and what does it do in JQuery_jquery

WBOY
Release: 2016-05-16 16:41:34
Original
1795 people have browsed it

First of all, let me explain jQuery jQuery has a handy little function for quickly loading javascript as DOM, that is ready... It is executed before the page is loaded.

Why not use window.onload(), because when the window.onload function is executed, it must indicate that everything has been loaded, including images, banners, etc. You should know that the download speed of larger images will be slower, so users must wait for the large images to be downloaded before they can see the code effect of window.onload() execution, which takes a long time to wait, which is not what we want.

But $(document).ready(fn): binds a function to be executed when the DOM is loaded and ready for query and manipulation.

This is the most important function in the event module because it can greatly improve the response speed of web applications.

Simply put, this method is purely an alternative to registering events with the window.load event. By using this method, you can call the function you bound as soon as the DOM is loaded and ready to be read and manipulated. $(document).ready(function(){ // your code });

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

$(document).ready means to get the document object when it is ready. The meaning of the above code is to check the document object until it is allowed to be operated (Translator's Note: This is much faster than the window.onload() function, because the code can be executed as long as the document object is loaded, instead of Need to wait to see if the image download on the page has been completed) --- this is what we want.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template