Differences between jQuery (function () {}) and (function () {}) (jQuery) _ jquery

Source: Internet
Author: User
This article mainly introduces the differences between jQuery (function () {}) and (function () {}) (jQuery). For more information, see, I hope to help you. Jquery is an excellent Javascr into pt framework. Now we will discuss the functions executed after loading two pages in Jquery.

$ (Document). ready (function (){
// Write your code here...
}); The Code that runs when the DOM is loaded.

Can be abbreviated

JQuery (function (){
});

(Function ($) {}) (jQuery) What does it mean?
(Function (){
}) (JQuery );

It is actually executing the () (para) anonymous method, but passing the jQuery object.

Equivalent
Function aa ($ ){}
Aa (jQuery)

Is the usual method for initializing jquery objects.

In layman's terms, the code you need is executed after the page is loaded.
However, this may sometimes make the page beat. Many JQUERY plug-ins change the style only after loading is complete, and the page will feel beating or flashing. for example, ui. the tab plug-in, where there are multiple page elements, all of which are displayed to form a TAB.

(Funtion () {}) (); execute the function immediately. It is equivalent to declaring a function and calling it directly after the declaration;

If the parameters are as follows:
(Funtion (str) {alert (str)}) ("output"); equivalent to: funtion OutPutFun (str) {alert (str );}; outPutFun ("output ");

JQuery (function () {}); used to store the code that operates the DOM object. When the code is executed, the DOM object already exists. It cannot be used to store the code of the Development plug-in. Because the jQuery object is not passed, the method (function) cannot be called externally through jQuery. method ).
(Function () {}) (jQuery); used to store the code of the Development plug-in. DOM does not necessarily exist when executing the code. Therefore, use the code that directly performs DOM operations with caution.

Related Article

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.