"$" Is the alias of jQuery (equivalent to simple writing), used to indicate that jQuery objects are called later. For example, $ ("div") and jQuery ("div"). The two statements are equivalent.
"$." Is also easy to understand. It is used to indicate that the jQuery method is called later. It is equivalent to "jQuery.". For example:
$. Trim ("like"); jQuery. trim ("like"); the two statements are equivalent. In addition, because "$" is the alias of jQuery, this symbol may conflict when multiple JavaScript libraries are referenced at the same time. JQuery provides the jQuery. noConflict () function to solve this problem. The following is the content of the api: jQuery. noConflict ()
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: This function must be used after you import the jQuery file and before importing another library that causes the conflict. Of course, it should also be before other conflicting libraries are used, unless jQuery is the last imported.
Example
Maps $ referenced objects back to the original objects.
JQuery code:
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:
Var j = jQuery. noConflict ();
// JQuery-based code
J ("div
P "). hide ();
// $ () Code based on other libraries
$ ("Content"). style. display = 'none ';
There is also a more powerful
JQuery. noConflict (extreme)
Return the control of $ and jQuery to the original library. Please be clear before using it!
This is a more challenging version than the simple noConflict method, because it will completely redefine jQuery. This is usually used in extreme cases, such as embedding jQuery in a highly conflicting environment. Note: after this method is called, the plug-in may become invalid.
--------------------------------------------------------------------------------
Revert control of both the $ and jQuery variables to their original owners. Use with discretion.
This is a more-extreme version of the simple noConflict method, as this one will completely undo what jQuery has introduced. this is to be used in an extreme case where you 'd like to embed jQuery into a high-conflict environment. NOTE: It's very likely that plugins won't work after this particle method has been called.
Return Value
JQuery
Parameters
Extreme (Boolean): Input true to allow the jQuery variable to be completely restored
Example
Move jQuery to a new namespace.
JQuery code:
Var dom = {};
Dom. query = jQuery. noConflict (true );
Result:
// New jQuery code
Dom. query ("div p"). hide ();
// Code of another database $ ()
$ ("Content"). style. display = 'none ';
// Code of jQuery of another version
JQuery ("div> p"). hide ();