jQuery mouseenter() Method

Last Updated:

jQuery mouseenter() Method

The jQuery mouseenter() method is used for the following 2 purpose

  1. To run a callback when a mouse entered a specified element.
  2. To trigger the mouseenter event of a specified element.

Run a Callback

In the following example, we will run a callback function when a mouse entered a specified element.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery mouseenter() Method</h1> <p>Try to touch me.</p> <script> $(document).ready(function(){ $("p").mouseenter(function(){ alert("Paragraph is touched."); }); }); </script> </body> </html>

Syntax

$(selector).mouseenter(callback);

Parameter Values

ValueTypeExplanation
callback Optional Specifies a function to be called once user enter the element.

Browser Support

Devicedesktopmobile
Browsergoogle chromesafarifirefoxinternet Exploreredgeoperagoogle chromesafarifirefoxedgeoperaandroid webviewsamsung internet
mouseenter()YesYesYesYesYesYesYesYesYesYesYesYesYes

Trigger a mouseenter Event

In the following example, we will trigger a mouseenter event when a button is clicked.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> </head> <body> <h1>jQuery mouseenter() Method</h1> <p>Try to touch me.</p> <button>Trigger mouseenter Event</button> <script> $(document).ready(function(){ $("p").mouseenter(function(){ alert("Paragraph is touched."); }); $("button").click(function(){ $("p").mouseenter(); }); }); </script> </body> </html>

mouseover() vs mouseenter()

Check out the difference between mouseover() vs mouseenter() in jquery.

Share this Page

Meet the Author