How to solve jquery dollar sign conflict

Source: Internet
Author: User

As follows:Code:

Copy code The Code is as follows: jquery. noconflict ();
Jquery (document). Ready (function (){

// Your code ....

});

Jquery. noconflict () Details:
Overview
Run this function to assign control of variable $ to the first database that implements it. This helps ensure that jquery does not conflict with the $ object of other libraries. After running this function, only jquery variables can be used to access jquery objects. For example, to use $ ("Div P"), you must replace it with jquery ("Div P ").
Note: This function must be used after you import the jquery file and before importing another library that causes the conflict. Of course, it should also be before other conflicting libraries are used, unless jquery is the last imported.
Description:
Maps $ referenced objects back to the original objects.
Jquery code:Copy codeThe Code is as follows: jquery. noconflict ();
// Use jquery
Jquery ("Div P"). Hide ();
// Use $ () for other libraries ()
$ ("Content"). style. Display = 'none ';

Description:
Resume the use of Alias $, and then create and execute a function. In the scope of this function, $ is still used as the alias of jquery. In this function, the original $ object is invalid. This function is very effective for most plug-ins that do not depend on other libraries.
Jquery code:Copy codeThe Code is as follows: jquery. noconflict ();
(Function ($ ){
$ (Function (){
// Use $ as the jquery alias code
});
}) (Jquery );
// Other code of the database that uses $ as the alias

Description:
Create a new alias to use the jquery object in the following library.
Jquery code:Copy codeThe Code is as follows: var J = jquery. noconflict ();
// Jquery-based code
J ("Div P"). Hide ();
// $ () Code based on other libraries
$ ("Content"). style. Display = 'none ';

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.