How to solve jQuery conflict problem

How to solve jQuery conflict problem

In front-end development, $ is a function in jQuery. If the parameters of $ are different, the functions implemented are different. During programming, $, as a symbol, may conflict with defined names in other files. So how do we handle this conflict? This article introduces two methods:

1. Solve the problem by releasing the right to use the $ symbol in the jQuery framework;

2. Solve using custom access symbols.

Method 1: Releasing the right to use the $ symbol in the jQuery framework

Processing instructions: $ is just an alias of jquery. If you need to use another js library other than jquery, you can return control to the library by calling $.noConflict().

jQuery.noConflict();
jQuery(function () {
   alert("hellow")
 });

Note: The release operation must be written before writing other jQuery codes, and after the release, $ cannot be used, use jQuery instead.

Method 2: Use custom access symbols to solve

Processing instructions: Customize a nj to replace the function of $

var nj =jQuery.noConflict();
nj(function(){
  alert("hello inj custom access symbol")
});

This is the end of this article on how to solve the jQuery conflict problem. For more information on how to deal with the jQuery conflict problem, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to the conflict problem of jquery UI Datepicker time control
  • $ symbol conflict problem and solution in jQuery
  • jQuery solves the conflict between the blur event of the input element and the click event of other non-form elements
  • Solution to the conflict between transport.js and jQuery
  • How to solve the $ usage conflict problem when importing extjs and jquery files
  • Solve the dollar sign naming conflict in jQuery

<<:  Nginx proxy forwarding implementation code uploaded by Alibaba Cloud OSS

>>:  MySQL 5.7.10 winx64 installation and configuration method graphic tutorial (win10)

Recommend

How to display the border when td is empty

Previously, I summarized how to use CSS to achieve...

MySQL character set viewing and modification tutorial

1. Check the character set 1. Check the MYSQL dat...

MySQL 5.7.17 installation and configuration graphic tutorial

Features of MySQL: MySQL is a relational database...

Detailed explanation of identifying files with the same content on Linux

Preface Sometimes file copies amount to a huge wa...

Docker installation and deployment example on Linux

After reading the following article, you can depl...

VMware12 installs Ubuntu19.04 desktop version (installation tutorial)

1. Experimental description In the virtual machin...

Solution to VMware virtual machine no network

Table of contents 1. Problem Description 2. Probl...

The principle and application of ES6 deconstruction assignment

Table of contents Array destructuring assignment ...

How to install Nginx and configure multiple domain names

Nginx Installation CentOS 6.x yum does not have n...

A quick guide to MySQL indexes

The establishment of MySQL index is very importan...

Five ways to traverse objects in javascript Example code

Table of contents Prepare Five weapons for…in Obj...

Vue implements a shopping cart that can change the shopping quantity

This article shares with you how to use Vue to ch...

Detailed explanation of how to install MySQL on Alibaba Cloud

As a lightweight open source database, MySQL is w...