To resolve the conflict between jquery and the $ () function in other JavaScript libraries, the $ () function of jquery needs to be canceled, and jquery provides the following methods:
Copy Code code as follows:
Cancel the $ () function in jquery
Jquery.noconflict ();
Place the above bold character code in the first line of JavaScript code, and this line of code cancels the jquery $ () function
Note: In fact, only the $ () alias for the jquery () function is canceled, so we can still use jquery instead of the original $ ().
In addition, repeated writing of jquery () is cumbersome, and jquery allows developers to specify their own aliases for jquery (), as shown in the following code:
Copy Code code as follows:
<body>
<div id= "Lee" ></div>
<script type= "Te Xt/javascript "src=". /jquery-1.10.2.js ">
</script>
<script type=" Text/javascript ">
//to the jquery () function to specify an alias for Lee
var lee = Jquery.noconflict ();
var target = Lee ("#lee")
target.html ("I Want to learn jquery")
. Height
. Width (160)
. CSS ("border", "2p X solid black ")
. CSS (" Background-color "," #ddddff ")
. CSS (" padding ", 20);
</script>
</body>