Two solutions for the conflict between jquery and JS functions

Source: Internet
Author: User

If you have other requirements, you want to continue to use the original $ (), but also need to be with other classes library does not conflict, there are two ways to solve

One

Jquery.noconflict ();  
jquery (function ($)  
{  
$ ("P"). Click (function ()///The $ () method for the JQuery class library can be used within a function  
{  
alert ($ (this). Text ()) ;  
})  
})  
      
var JSCOM_CR = $ ("Cr"); Outside the function, you can use the $ () method of the Jscom.js

Second:

Jquery.noconflict (); When you transfer the control of a variable $ to another class library, use jquery ("#id")  
when using the $ symbol for the jquery class library. (function ($) {///define anonymous function and set the parameter to $ $  
(function () {///The inside of the anonymous function is jquery  
$ ("div"). Click (function () {//continue to use the $ () method  
Alert ($ (this). Text ()),  
})}  
)  
http://www.unitymanual.com/forum76.html Unity3d Game  
(jquery);//Use anonymous functions and pass the argument jQuery  
alert ($ ("Cr")); Using the $ () function in the Jscom.js class library

More Wonderful content: http://www.bianceng.cn/webkf/jquery/

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.