Home > Web Front-end > JS Tutorial > Parsing jQuery and other js (Prototype) libraries for compatibility and coexistence_jquery

Parsing jQuery and other js (Prototype) libraries for compatibility and coexistence_jquery

WBOY
Release: 2016-05-16 17:30:23
Original
951 people have browsed it
1. After running this function, you can resume using the alias $ and still use $ as an alias for jQuery in the scope of this function.
jQuery Code:
Copy code The code is as follows:

jQuery.noConflict();
(function($) {
$(function() {
// Code that uses $ as jQuery alias
});
}) (jQuery);
// Code based on other libraries using $ as alias

2. After running this function, you can create a new jQuery alias to replace the original jQuery Alias ​​$ to use.
jQuery Code:
Copy code The code is as follows:

var j = jQuery.noConflict();
// Code using the new alias jQuery
j("div p").hide();
// Using $ as an alias based on other libraries The code of
$("content").style.display = 'none';

Note: This function must be imported after you import jQuery file and before importing another library that causes a conflict.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template