Did you find this useful?
Socialize it today.


jQuery noConflict Method

Friday, July 20, 2012

There are other JavaScript libraries that use $ as a function or variable name, just as jQuery does. With regard to jQuery, the $ is just an alias for jQuery. If we need to use another JavaScript library alongside jQuery, we can return control of $ back to the other library with a call to $.noConflict(). This method can also be used to specify a new custom name for the jQuery variable.


Example

We will use the following HTML for the examples listed below.


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">

  // ... jQuery Code ...

</script>
</head>
<body>
 <img id="img1" src="go.png" /> ; 
 <div id="div1"> <!-- Some Content --> </div>
</body>
</html>


Syntax

$.noConflict(removeAll)


ParameterDescription
removeAllBoolean value indicating whether to remove all jQuery variables from the global scope (including jQuery itself).


var jq=$.noConflict();
jq(document).ready(function(){
  jq("#img1").click(function(){
    jq("#div1").text("You implemented the noConflict method!");
  });
});


click here


Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Pro jQuery HTML CSS and JavaScript Editor Professional jQuery