jQuery noConflict()

Introduction

Use the noConflict() method to specify a new name for the jQuery variable:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
var jq = $.noConflict();/*from w  w  w  . j  a  v  a  2s.co  m*/
jq(document).ready(function(){
  jq("button").click(function(){
      jq("p").hide();
  });
});
</script>
</head>
<body>

<h2>This is a heading</h2>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<button>Click me</button>

</body>
</html>

The noConflict() method can rename jQuery's $ variable.

We can specify a new custom name for the jQuery variable.

This method is useful when other JavaScript libraries use the $ for their functions.

$.noConflict(remove_All)
Parameter
Optional
Data Type
Description
remove_All
Optional.
A Boolean value
whether or not to release jQuery's control of ALL jQuery variables including "jQuery"



PreviousNext

Related