Home >>jQuery Tutorial >jQuery hover() Method

jQuery hover() Method

jQuery hover() Method

jQuery hover() method in jQuery is an inbuilt method which is used to execute two functions while the mouse pointer is hovering over the selected elements and the second event handler function executes when mouse pointer leaves the selected element.

Syntax:
$(selector).hover(inFunction,outFunction)

Parameter Values

Parameter Description
inFunction It is a required parameter and is used to specifies the function to run when the mouseenter event occurs
outFunction It is optional parameter and is used to specifies the function to run when the mouseleave event occurs
Here is an Example of jQuery hover() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".txt").hover(function(){
$(this).css("background-color", "dodgerblue");
}, function(){
$(this).css("background-color", "orange");
});
});
</script>
</head>
<body>
<p class="txt">Hover me with mouse pointer !</p>
</body>
</html>

Output:

Hover me with mouse pointer !


No Sidebar ads