Open In App

jQuery mouseover() Method

Last Updated : 18 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

The jQuery mouseover() method is an inbuilt method which works when mouse pointer moves over the selected elements. 

Syntax:

$(selector).mouseover(function)

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

Example 1: This example illustrates the use of mouseover() method.

HTML




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


Output: 

 

Example 2: In this example, a pop-up will come out when the mouse moves over the paragraph.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>The mouseover Method</title>
    <script src=
    </script>
  
    <!-- jQuery code to show the working of this method -->
    <script>
        $(document).ready(function () {
            $("p").mouseover(function () {
                alert("Mouse moved over this paragraph");
            });
        });
    </script>
    <style>
        body {
            width: 280px;
            padding: 40px;
            height: 30px;
            border: 2px solid green;
            font-weight: bold;
            font-size: 20px;
        }
    </style>
</head>
  
<body>
    <!-- move over this text and pop-up will come out -->
    <p>Welcome to GeeksforGeeks!</p>
</body>
  
</html>


Output:

 

Related Articles:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads