Tutorialspoint.dev

jQuery | mouseleave() with Examples

The mouseleave() method is an inbuilt method in jQuery which works when the mouse pointer leaves the selected element.

Syntax:

$(selector).mouseleave(function)

Parameters: This method accepts single parameter function which is optional. It is used to specify the function to run when the mouseleave event is called.

Return Value: This method returns the selected element with the changes made by mouseleave() method.

Below example illustrates the mouseleave() method in jQuery:



Example:

<!DOCTYPE html>
<html>
    <head>
        <title>The mouseleave Method</title>
        <script src=
        </script>
          
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function() {
                $("p").mouseleave(function() {
                    $("p").css("background-color", "lightgreen");
                });
            });
        </script>
        <style>
            body {
                width: 300px;
                padding: 40px;
                height: 30px;
                border: 2px solid green;
                font-weight: bold;
                font-size: 20px;
            }
        </style>
    </head>
       
    <body>
        <!-- move over this paragraph and see the change -->
        <p>Welcome to GeeksforGeeks!</p>
    </body>
</html>

Output:
Before moving mouse over paragraph:

After moving mouse over the paragraph.

Related Articles:



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter