初心者向けjQuery入門

初心者向けjQuery入門講座です

未分類

jQuery mouseenterとmouseleaveマウスイベントの方法

投稿日:2017年8月28日 更新日:

jQuery mouseenterとmouseleaveマウスイベントの方法

jQuery mouseenterマウスを乗せた時のイベント方法

mouseenterはマウスを乗せた時に発生するイベントです。

サンプル

$(function(){

$(“.セレクタ”).mouseenter(function(){

処理

 

});

});

サンプル

<html>

<head>

<script src=”jquery-3.2.1.js”></script>
<script>$(function(){

$(“.botton”).mouseenter(function(){ $(“.three”).css(“color”,”red”)

 

});

});

</script>

<title>
</title>

</head>

<body>
<input type=”button” value=”botton” class= “botton” >

<div>
<ul><li>1</li>

<li >2</li>

<li class=”three”>3</li>

<li>4</li>

<li>5</li>

</ul>

</div>

 

</body>

</html>

実行結果は

ボタンに乗せた時に3が赤くなります。

一回乗せたらそのまま赤くなったままです。

jQuery mouseleaveマウスイベント外した時のイベントの方法

mouseleaveはマウスを外した時に発生するイベントです。

 

サンプル

$(function(){

$(“.botton”).mouseleave(function(){ $(“.three”).css(“color”,”black”)

 

});

});

サンプル

<html>

<head>

<script src=”jquery-3.2.1.js”></script>
<script>$(function(){

$(“.botton”).mouseenter(function(){ $(“.three”).css(“color”,”red”)

 

});
$(“.botton”).mouseleave(function(){ $(“.three”).css(“color”,”black”)

 

});
});

</script>

<title>
</title>

</head>

<body>
<input type=”button” value=”botton” class= “botton” >

<div>
<ul><li>1</li>

<li >2</li>

<li class=”three”>3</li>

<li>4</li>

<li>5</li>

</ul>

</div>

 

</body>

</html>

実行結果は

ボタンを乗せると赤になり外すと黒になります。

mouseenterとmouseleaveのイベントの発生要素は指定した要素だけです。

 

スポンサードリンク




スポンサードリンク




-未分類
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

jQuery wrapとunwrap親要素を追加と削除

jQuery wrapとunwrap親要素を追加と削除 jQuery wrap 親要素を追加 wrapは親要素を追加します サンプル $(“セレクタ”).wrap(&#8216 …

no image

jQuery チルダ~の間接セレクタと兄弟セレクタ

jQuery チルダ~の間接セレクタと兄弟セレクタ jQuery チルダ~の間接セレクタと兄弟セレクタ 間接セレクタはチルダを使用します。 兄弟とは親が同じだということですね。 動作は指定した兄弟の以 …

no image

jQuery beforeとafterの違いと要素の追加

jQuery beforeとafterの違いと要素の追加 jQuery beforeとafterの違い beforeとafterは基本的な動作は似てます。 共通してるのは要素を追加することです。 違う …

no image

jQuery clickクリックイベントの書き方

clickクリックイベントの書き方 clickクリックイベントの書き方 クリックイベントの書き方の前にイベントの書き方を解説します。 サンプル $(function(){ $(“セレクタ& …

no image

jQuery attrとremoveAttr属性の取得と設定と削除

jQuery attrとremoveAttr属性の取得と設定と削除 attrはattributeの略ですね。 英語で属性という意味です。 jQuery attr属性の設定する サンプル $(&#822 …