jQuery mouse events mouseover() and mouseout() events
When you were learning JS, do you still remember that there are two methods called move-in and move-out events? onmouseover() and onmouseout() events~
jQuery also provides such events to monitor the user's move-in and move-out operations. The mouseover() and mouseout() events are similar in usage
Let's explain it through an example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>mouseover()和mouseout()</title> <style type="text/css"> div{ width:200px; height:200px; border:1px solid #000; } </style> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <div></div> <script> $("div").mouseover(function(){ $('div').css("background",'red'); }) $("div").mouseout(function(){ $('div').css("background",'green'); }) </script> </body> </html>
When the mouse is placed on the div tag, the background color will turn red, and when the mouse leaves the div tag, it will turn green