JQuery self-study notes-7 $ symbol rules

Source: Internet
Author: User

As you have learned, jQuery uses the $ symbol as short for jQuery. What if other JavaScript frameworks use the $ symbol for short? Other JavaScript frameworks include: MooTools, Backbone, Sammy, Cappuccino, Knockout, JavaScript MVC, Google Web Toolkit, Google Closure, Ember, Batman, and Ext JS. Some frameworks also use the $ symbol as short form (like jQuery). If the two frameworks you are using use the same short form symbol, the script may stop running. The jQuery team considered this issue and implemented the noConflict () method. The jQuery noConflict () method noConflict () will release the control of $ identifier, so that other scripts can use it. Of course, you can still use jQuery: $. noConflict (); jQuery (document ). ready (function () {jQuery ("button "). click (function () {jQuery ("p "). text ("jQuery is still running! ") ;}); You can try the instance yourself or create your own shorthand. NoConflict () returns a reference to jQuery. You can save it to a variable for later use. See this example: var jq = $. noConflict (); jq (document ). ready (function () {jq ("button "). click (function () {jq ("p "). text ("jQuery is still running! ") ;}); Try it for yourself. If your jQuery code block is abbreviated as $, and you do not want to change this shortcut, you can pass the $ symbol as a variable to the ready method. In this way, you can use the $ symbol in the function. In addition to the function, you still have to use "jQuery": $. noConflict (); jQuery (document ). ready (function ($) {$ ("button "). click (function () {$ ("p "). text ("jQuery is still running! ") ;}); Give it a try.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.