The difference between $ (document). ready (function () {}); and $ (). ready in the script

Source: Internet
Author: User

The difference between $ (document). ready (function () {}); and $ (). ready in the script

$ (Document ). the code in ready () is executed only after the page content is loaded. If you directly write the code to the script tag, after the script tag is loaded on the page, the code in it will be executed. If the code executed in your tag calls the code or dom that has not been loaded yet, an error will be reported, of course, if you put the script tag at the end of the page, there will be no problem. This is the same as ready.

$ (Document). ready (function () {}) can be abbreviated to $ (function (){});


After clicking a paragraph, this paragraph is hidden:


If you remove $ (document). ready (function () {});, the Section cannot be hidden:


However, if you put the script at the end of the page, the hiding effect can be restored:





$ (Document) ready (function () {}); what is the difference between writing and not writing?

$ (Document ). the code in ready is executed only after the page content is loaded. You can directly write it to the script tag. After the script tag is loaded on the page, the code in the script will be executed, if the code executed in your tag calls the code or dom that has not been loaded yet, an error will be reported,
Of course, if you set the script tag to the end of the page, there will be no problem with ready.

In jquery, what is the difference between $ (document) ready (function () {}); and $ () ready (function?

Shorthand
$ (Document). ready (function (){});
$ (). Ready (function (){});
Yes
$ (Function () {}) is the shortest ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.