Solution to jQuery Conflict Problem

  • 2021-10-24 18:39:28
  • OfStack

In front-end development, $is a function in jQuery. If the parameters of $are different, the functions are different. During programming, as a symbol, $may conflict with defined names in other files. How to deal with this conflict? This site in this article introduces two methods:

1. It is solved by releasing the right to use the $symbol in jQuery framework;

2. Use custom access symbols to solve the problem.

Method 1: Resolve by releasing the right to use the $symbol in the jQuery framework

Handling instructions: $is just a 1 alias for jquery, and if you need to use a 1 js library other than jquery, you can return control to that library by calling $. noConflict ().

jQuery(function () {

Note: The release operation must be written before the other jQuery code is written, and after the release, you cannot use $and use jQuery instead.

Method 2: Use custom access symbols to solve

Handling instructions: Customize 1 nj to replace the function of $

var nj =jQuery.noConflict();
  alert("hello inj  Custom access symbols ")

Related articles: