mouseleave() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:mouseleave

Description

The mouseleave() method triggers the mouseleave event, or sets function as mouseleave event handler.

Syntax

$(selector).mouseleave(function);
Parameter RequireDescription
function Optional.function to run when the mouseleave event is triggered

The following code shows how to set the background color to gray, when the mouse pointer leaves a <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").mouseenter(function(){
        $("p").css("background-color", "yellow");
    });/*from w  w  w  . j ava2 s.com*/
    $("p").mouseleave(function(){
        $("p").css("background-color", "lightgray");
    });
});
</script>
</head>
<body>

<p>Move the mouse pointer over this paragraph.</p>

</body>
</html>

Related Tutorials