Compatibility and conflict between jquery and prototype

Source: Internet
Author: User

First, load prototype and then jquery.
Method 1: The jquery library and all its plug-ins are in the jquery namespace, and global variables are also stored in the jquery namespace.

Use jquery. noconflict (); it can be called at any time after jquery is loaded, and the $ symbol's right to use is returned to other JS libraries, when jquery creates its own namespace, it saves $ of other libraries in its own variable.

<HTML> 

Method 2: If you still want to use a short character like $, you can assign the return value of jquery. noconflict () to a variable. This variable is short for jquery. Of course you can use any string other than $, for example:

<HTML> 

Method 3: If you still want to use $ instead of other characters, you can. Generally, programmers prefer to do this, because almost all the code written in this way does not need to replace the original $ symbol. The concept of namespace is used to encapsulate all jquery code in the ready event namespace range of the document, such as jquery (document). Ready (enter jquery code here)

<HTML> 

Case 2: First load jquery and then load prototype

Loading in this order does not cause the $ symbol of other JS libraries to be occupied by jquery. Therefore, the code of other JS libraries can be used as usual without any modification. jquery can be used to replace $. For example:

<HTML> 

Or if you don't want to write such long characters as jquery, you can use another method:

 var  $j = jQuery;

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.