jQuery Tutorial
jQuery hover binds handlers for both mouse enter 'mouseEnter' and mouse leave 'mouseLeave' events.
.hover(over, out)
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title>jQuery hover method</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript"> $(document).ready(function () { $("div").hover(function () { $(this).css("background-color", "red"); }); }); </script> </head> <body> <div style="height:200px;width:200px;background-color:blue;color:white"> Mouse move in this area </div> </body> </html>Output:
Move the mouse on "Move mouse in this area" div and see the div background color changes from blue to red.
This jQuery code is used to handle the common functionality to display the page positions x and y when mouse enter on the div area and leave on the div area.
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title>jQuery hover method</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type="text/javascript"> $(document).ready(function () { $("div").hover(function (event) { $(this).text("x: " + event.pageX + " y: " + event.pageY); }); }); </script> </head> <body> <div style="height:200px;width:200px;background-color:blue;color:white"> Mouse move in this area </div> </body> </html>Output:
Move the mouse on "Move mouse in this area" div to get the mouse positions inside div and leave the div to see the outside mouse positions.
« Previous Next » jQuery Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page