jquery mouseoutでマウスが外れた時のイベントを取得する
環境
Google Chrome 105.0.5195.127
Windows 10 Home 64bit
jquery 3.6.1
構文
$('指定要素’).on('mouseout’, function () {処理コード}
onメソッドにmouseoutを使用してマウスが外れた時のイベントを取得します。
$('指定要素').on('mouseover', function () {処理コード}
onメソッドにmouseoverを使用してマウスがオーバーされた時のイベントを取得します。
$('指定要素').on('mouseover', function () {処理コード}
onメソッドにmouseoverを使用してマウスがオーバーされた時のイベントを取得します。
$('指定要素').on('mouseover', function () {処理コード} onメソッドにmouseoverを使用してマウスがオーバーされた時のイベントを取得します。
使用例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#cft').on('mouseout', function () {
$("#result").text('マウスアウトされました');
})
$('#cft').on('mouseover', function () {
$("#result").text('マウスオーバーされました');
})
});
</script>
</head>
<body>
<h2 id="result"></h2>
<a id="cft">東京</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#cft').on('mouseout', function () {
$("#result").text('マウスアウトされました');
})
$('#cft').on('mouseover', function () {
$("#result").text('マウスオーバーされました');
})
});
</script>
</head>
<body>
<h2 id="result"></h2>
<a id="cft">東京</a>
</body>
</html>
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <script> $(document).ready(function(){ $('#cft').on('mouseout', function () { $("#result").text('マウスアウトされました'); }) $('#cft').on('mouseover', function () { $("#result").text('マウスオーバーされました'); }) }); </script> </head> <body> <h2 id="result"></h2> <a id="cft">東京</a> </body> </html>
実行結果
指定した要素「id=”cft″」からマウスが外れれば「マウスアウトされました」と表示します。