Home  >  Article  >  Web Front-end  >  A quick solution to the conflict between JQuery's $ and other JS_jquery

A quick solution to the conflict between JQuery's $ and other JS_jquery

WBOY
WBOYOriginal
2016-05-16 17:02:44878browse

As we all know, jQuery is currently the most popular JS package, which simplifies many complex JS programs. JQuery defines the browser DOM tree as $, and uses $ to obtain each child node.

Then, JS plug-ins are not only JQuery, but also prototype.js and other better plug-ins. They also use $. So sometimes when these two JS plug-ins are used at the same time, there will be a conflict of usage rights of $. Now let's see how to resolve this conflict. Please see below:

We all know that JQuery has a function, jquery.noConflict(). Its function is to transfer the control of $. Then we can use jQuery instead of $ to get the dom node

Example:

Method 1:

Copy the code The code is as follows:



Method 2:

We can use the noConflict() function to define a shortcut to get the dom node

Copy the code The code is as follows:



and other methods are listed here. Come out, you can understand the same thing, haha.

Method three:

Copy the code The code is as follows:



method Four:
Copy code The code is as follows:


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn