jQuery Misc-noConflict()
0 1113
- This jQuery method is used to stop the confliction from the uses of $ symbol by different jQuery frameworks.
- This method let out the control of $ variable from jQuery library so that other custom library can use it without any disturbance in any functionality.
Related Topics:
jQuery ajax-getJSON
jQuery form-serializeArray
jQuery Misc-noConflict
Syntax:
$.noConflict(removeAll);
Parameter description:
Example: 1
In this example we will replace the $ variable from con.
<html>
<head>
<title> jQuery Example </title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<style>
div{
background:pink;
font-weight: 700;
padding:5px;
margin:5px;
font-size:16px;
}
p{
background:yellow;
padding:5px;
margin:5px;
}
button{
background:green;
padding:10px;
color:white;
border:1px solid green;
}
</style>
<script>
var con = $.noConflict();
con(document).ready(function(){
con("button").click(function(){
con("#res").html("<p>Welcome to Coding Tag.</p>");
});
});
</script>
</head>
<body>
<h2> jQuery noConflict() method Example </h2>
<div id="res">
This content will be replaced....
</div>
<button> Click Me! </button>
</body>
</html>
Output:
When you click the button,
Example: 2
In this example we will run jQuery with con variable and other with other custom variable simultaneously.
<html>
<head>
<title> jQuery Example </title>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js"></script>
<script type = "text/javascript"
</script>
<style>
.d{
background:pink;
font-weight: 700;
padding:5px;
margin:5px;
font-size:16px;
}
.p{
background:yellow;
padding:5px;
margin:5px;
}
button{
background:green;
padding:10px;
color:white;
border:1px solid green;
}
</style>
<script>
var con = $.noConflict();
con(document).ready(function(){
con("#b1").click(function(){
con("div").addClass("d");
con("p").addClass("p");
alert("Class added successfully");
});
});
document.observe("dom:loaded", function(){
$("b2").observe("click", function(event){
alert("Custom library working fine");
});
});
</script>
</head>
<body>
<h2> jQuery noConflict() method Example </h2>
<div>
<p id="myp"> Welcome to Coding Tag. </p>
</div>
<button id="b1"> With con add class to div element </button> | <button id="b2"> Run custom library </button>
</body>
</html>
Output:
When you click first button,
When you click second button,
Share:
Comments
Waiting for your comments