How to resolve conflicts between jquery Library and other libraries

Source: Internet
Author: User

When developing with jQuery, other JS libraries or plug-ins, such as Prototype, may be used. However, conflicts may occur when multiple libraries coexist, leading to various accidents. Next we will share with you several solutions to conflicts between jquery libraries and other libraries.

1. The jQuery library is imported before other libraries, and the jQuery (callback) method is used directly as follows:

<Html xmlns = "http://www.phpernote.com/php-function/849.html"> 

2. The jQuery library is imported after other libraries. The jQuery. noConflict () method is used to transfer the control of variable $ to other libraries. The following methods are available:

(1) method 1

<Script type = "text/javascript"> var $ j = jQuery. noConflict (); // customize a short shortcut $ j (function () {// use jQuery $ j ("p "). click (function () {alert ($ j (this ). text () ;}) ;}; $ ("p "). style. display = 'none'; // use prototype </script>

(2) method 2

<Script type = "text/javascript"> jQuery. noConflict (); // assign control of variable $ to prototype. jsjQuery (function ($) {// use jQuery $ ("p "). click (function () {// continue to use the $ method alert ($ (this ). text () ;}) ;}; $ ("p "). style. display = 'none'; // use prototype </script>

(3) method 3

<Script type = "text/javascript"> jQuery. noConflict (); // assign control of variable $ to prototype. js (function ($) {// defines an anonymous function and sets the parameter to $ (function () {// $ inside the anonymous function is jQuery $ ("p "). click (function () {// continue to use the $ method alert ($ (this ). text () ;};}) ;}( jQuery); // executes an anonymous function and passes the real parameter jQuery $ ("p "). style. display = 'none '; // use prototype /*********************************** * *********************************/jQuery (document ). ready (function () {// get the right out of jQuery when loading the page. noConflict () ;}); </script>
Articles you may be interested in
  • How to solve conflicts between concurrent read/write files in php
  • Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
  • Windows cannot start the hardware device because its configuration information (in the Registry) is incomplete or damaged. (Code 19) Solution
  • SetTimeout does not support other jquery selectors such as $ (this ).
  • Rational use of MySQL database indexes to make the database run efficiently
  • MySQL index Operation Command (create index, re-index, query index, delete index) Summary
  • Js can only enter numbers and numbers with decimal points, compatible with IE and firefox
  • Js shields mouse and keyboard events (including right-click, direction key, backspace key, F5 refresh key, etc.), compatible with IE and firefox

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.