初心者向け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 attrとremoveAttr属性の取得と設定と削除

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

no image

jQuery prevALLとnextALL前と後の兄弟要素を全て取得する

jQuery prevALLとnextALL前と後の兄弟要素を全て取得する jQuery prevALL前の兄弟要素を全て取得する prevALLメソッドは指定した前の兄弟要素を全て取得します。 サン …

no image

jQuery firstとlast最初と最後の要素を取得する

jQuery firstとlast最初と最後の要素を取得する jQuery first最初の要素を取得する firstメソッドは最初の要素を取得します。 サンプル $(“セレクタ&#822 …

no image

疑似クラスと疑似要素

疑似クラスと疑似要素 疑似クラス 疑似クラスとは疑似的に処理をセレクタに追加するものです。 :をつけます。 疑似クラス一覧 :active :any :checked :default :dir() …

no image

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

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