Ways to get jquery to coexist with other JavaScript libraries to avoid conflicts

Source: Internet
Author: User

To solve the conflict between jquery and the $ () function in other JavaScript libraries, the $ () function of jquery needs to be canceled, and here's a good way to find out what friends are interested in

To resolve the conflict between jquery and the $ () function in other JavaScript libraries, the $ () function of jquery needs to be canceled, and jquery provides the following methods: The code is as follows://Cancel the $ () function in jquery jquery.noconflict ();    Put the bold text code in the first line of JavaScript code, and this line of code will cancel jquery's $ () function Note: In fact, it only cancels the $ () alias for the jquery () function, so we can still use jquery instead of the original $ (). In addition, multiple repetitions of jquery () are also cumbersome, and jquery allows developers to specify their own aliases for jquery (), as shown in the following code: The code is <div id= "Lee" ></div > <script type= "text/javascript" src= ". /jquery-1.10.2.js "> </script> <script type=" Text/javascript ">//To the jquery () function to specify the alias for lee var Lee = jquery.no  Conflict (); var target = Lee ("#lee") target.html ("I Want to learn jquery"). Height (160). CSS ("Border", "2px solid Black"). CSS ("b  Ackground-color "," #ddddff "). CSS (" padding ", 20); </script> </body>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.