Jquery. noconflict ()

Source: Internet
Author: User

Run this function to assign control of variable $ to the first database to implement it.

This helps ensure that jquery does not conflict with $ objects in other libraries.

<SCRIPT type = "text/JavaScript" src = "/javascripts/jquery. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
VaR J $ =$;
Jquery. noconflict ();
</SCRIPT>

<SCRIPT type = "text/JavaScript" src = "/javascripts/prototype. js"> </SCRIPT>

After running this function, you can only use jquery variables to access jquery objects. For example, to use $ ("Div P"), you must replace it with J $ ("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.

 

Method 1:

Jquery. noconflict ();

// Use jquery

J $ ("Div P"). Hide ();

// Use $ () for other libraries ()

$ ("Content"). style. Display = 'none ';

 

Method 2:

// My website viqiwu.com

VaR viqiwu = jquery. noconflict ();

// Jquery-based code

Viqiwu ("Div P"). Hide ();

// $ () Code based on other libraries

$ ("Content"). style. Display = 'none ';

In this way, you don't have to worry about jquery conflicts with other JS frameworks.

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.