「jQuery入門」noConflict()を使うサンプル
説明
jQuery.noConflict()
noConflictを使った場合、jQueryオブジェクトの呼び出しには明確に’jQuery’と書く必要がある。
noConflict()メソッドは、$ショートカット識別子の保留を解除して、他のスクリプトがそれを使用できるようにします。
使用例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$.noConflict();
jQuery(document).ready(function(){
jQuery("button").click(function(){
jQuery(".cft").text("tesut message!");
});
});
</script>
</head>
<body>
<div class="cft">これはdivです.</div>
<button>テスト</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$.noConflict();
jQuery(document).ready(function(){
jQuery("button").click(function(){
jQuery(".cft").text("tesut message!");
});
});
</script>
</head>
<body>
<div class="cft">これはdivです.</div>
<button>テスト</button>
</body>
</html>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> $.noConflict(); jQuery(document).ready(function(){ jQuery("button").click(function(){ jQuery(".cft").text("tesut message!"); }); }); </script> </head> <body> <div class="cft">これはdivです.</div> <button>テスト</button> </body> </html>