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

JS object copying (deep copy and shallow copy)

Table of contents 1. Shallow copy 1. Object.assig...

jQuery custom magnifying glass effect

This article example shares the specific code of ...

A universal nginx interface to implement reverse proxy configuration

1. What is a proxy server? Proxy server, when the...

How to write the style of CSS3 Tianzi grid list

In many projects, it is necessary to implement th...

This article will help you understand JavaScript variables and data types

Table of contents Preface: Kind tips: variable 1....

MySQL database migration quickly exports and imports large amounts of data

Database migration is a problem we often encounte...

Web front-end development CSS related team collaboration

The front-end development department is growing, ...

How to Monitor Linux Memory Usage Using Bash Script

Preface There are many open source monitoring too...

This article will show you how to use Vue 3.0 responsive

Table of contents Use Cases Reactive API related ...

MySQL index knowledge summary

The establishment of MySQL index is very importan...

WeChat applet implements simple calculator function

WeChat applet: Simple calculator, for your refere...

How to configure NAS on Windows Server 2019

Preface This tutorial installs the latest version...

js object to achieve data paging effect

This article example shares the specific code of ...

Docker+selenium method to realize automatic health reporting

This article takes the health reporting system of...

JavaScript function detailed introduction

Any number of statements can be encapsulated thro...