初心者向け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 first-childとlast-childの勘違い

jQuery first-childとlast-child jQuery first-child first-childは一番最初の子要素を指定します。 $(“要素:first-child …

no image

jQuery 子孫セレクタとユニバーサルセレクタと複数

jQuery 子孫セレクタとユニバーサルセレクタと複数 jQuery 子孫セレクタ 子孫セレクタとは 要素には親要素と子要素があります。 ulだと子はliですね。 それとdivの中にp要素を入れ子にし …

no image

jQuery addclassクラスを追加する方法

jQuery addclassクラスを追加する方法 jQuery addclassクラスを追加する方法 addclassクラスは要素にクラスを設定できます。 どういうことかというこクラスのタブにhtm …

no image

jQuery slideUpとslideDownとslideToggle

jQuery slideUpとslideDownとslideToggle jQuery slideUp slideUpはスライドをアップします。 要素が上に上がっていき非表示になります。 サンプル $ …

no image

jQuery parentとchildren親と子要素を取得する

Query parentとchildren親と子要素を取得する Query parent 親要素を取得する parentは指定した要素の親要素を取得します、 サンプル $(“セレクタ&#8 …