jQuery mouseleave()
handle mouse leave event
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script>//from ww w. ja v a 2 s.c om <script> $(document).ready(function(){ $("p").mouseenter(function(){ $("p").css("background-color", "yellow"); }); $("p").mouseleave(function(){ $("p").css("background-color", "lightgray"); }); $("#btn1").click(function(){ $("p").mouseenter(); }); $("#btn2").click(function(){ $("p").mouseleave(); }); }); </script> </head> <body> <p>This is a paragraph.</p> <button id="btn1">Trigger mouseenter event</button><br> <button id="btn2">Trigger mouseleave event</button> </body> </html>