Jquery. noconflict () function,
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.
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 jquery ("Div P ").
Note:After you import the jquery file,In addition, when importing another library that causes conflictsBeforeUse(Luckymien note: the content in the lower part is inaccurate. This is not required in the new version of jquery ). Of course, it should also be before other conflicting libraries are used (luckymien Note: This sentence is undoubtedly correct), unless jquery is the last imported.
Example:
Maps $ referenced objects back to the original objects.
JqueryCode:
Jquery. noconflict ();
// Use jquery
Jquery ("Div P"). Hide ();
// Use $ () for other libraries ()
$ ("Content"). style. Display = 'none ';
Resume the use of Alias $, and then create and execute a function. In the scope of this function, $ is still used as the alias of jquery. In this function, the original $ object is invalid. This function is very effective for most plug-ins that do not depend on other libraries.
Jquery code:
Jquery. noconflict ();
(Function($){
$ (Function(){
// Use $ as the jquery alias code
});
}) (Jquery );
// Other code of the database that uses $ as the alias
Create a new alias to use the jquery object in the following library.
Jquery code:
VaRJ = jquery. noconflict ();
// Jquery-based code
J ("Div P"). Hide ();
// $ () Code based on other libraries
$ ("Content"). style. Display = 'none ';
Luckymien added: jquery. noconflict () has a deep parameter. If it is true, it can not only prevent the $ conflict, but also prevent the keyword conflict of jquery.
Jquery code:
VaRJ = jquery. noconflict (true );
// Jquery-based code
J ("Div P"). Hide ();
// $ () Code based on other libraries
$ ("Content"). style. Display = 'none ';
// Jquery () code based on other libraries (or versions)
Jquery ("# ABC" ).html ("this is rare! ");