jQuery hover()メソッド
例
<p>要素の上にマウスポインタを置いたときに、その要素の背景色を変更します。
$("p").hover(function(){
$(this).css("background-color", "yellow");
}, function(){
$(this).css("background-color", "pink");
});
定義と使用法
hover()メソッドは、マウスポインターが選択された要素の上にあるときに実行する2つの関数を指定します。
このメソッドは、mouseenterイベントとmouseleaveイベントの両方をトリガー します。
注: 1つの関数のみが指定されている場合、その関数は、mouseenterイベントとmouseleaveイベントの両方に対して実行されます。
構文
$(selector).hover(inFunction,outFunction)
Parameter | Description |
---|---|
inFunction | Required. Specifies the function to run when the mouseenter event occurs |
outFunction | Optional. Specifies the function to run when the mouseleave event occurs |