noConflict ile Çakışma Önlemek

Birden fazla jquery ile çalışan kütüphane eklerseniz bazıları çalışmayabilir. İşte çözümü…

JavaScript
27 lines
·<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
var $x = jQuery.noConflict();
$x(function(){
$x( ".a" ).click(function() {
$x( this ).css("background-color","yellow");
});
});
var $y = jQuery.noConflict();
$y(function(){
$y( ".a" ).click(function() {
$y( this ).css("color","red");
});
});
</script>
</head>
<body>
<div class="a">test</div>
</body>
</html>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX