Home >Web Front-end >JS Tutorial >How to solve jQuery$ naming conflict_jquery

How to solve jQuery$ naming conflict_jquery

WBOY
WBOYOriginal
2016-05-16 17:03:301049browse

Some other JavaScript frameworks include: MooTools, Backbone, Sammy, Cappuccino, Knockout, JavaScript MVC, Google Web Toolkit, Google Closure, Ember, Batman, and Ext JS.

Some of these frameworks also use the $ symbol as a shorthand (just like jQuery). If you are using two different frameworks that are using the same shorthand symbol, it may cause the script to stop running.

The jQuery team took this issue into consideration and implemented the noConflict() method.

Example

You can also create your own abbreviation. noConflict() returns a reference to jQuery that you can store in a variable for later use. Please look at this example:

Copy code The code is as follows:

var jq = $.noConflict( );
jq(document).ready(function(){
jq("button").click(function(){
jq("p").text("jQuery is still running! ");
});
});
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