The mouseover event is occurred when
you put your mouse cursor over the selected element .or we can say that The mouseover event
occurs when the mouse pointer is over the selected element.The mouseover()
method triggers the mouseover event, or attaches a function to run when a
mouseover event occurs.
Syntax:
Step 1. $(selector).mouseover()
It triggers the mouseover event for
selected elements.
Step 2. $(selector).mouseover(function)
It adds a function to the mouseover
event.
Example-1
<!DOCTYPE html><html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script>$(document).ready(function(){
$("p").hover(function(){
$(this).css("background-color", "red");
}, function(){
$(this).css("background-color", "green");
});
});
</script></head><body>
<p>roll the mouse Arrow over this text.</p>
</body></html>
Example-2
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").mouseover(function(){
$("p").css("background-color", "blue");
});
$("p").mouseout(function(){
$("p").css("background-color", "green");
});
});
</script>
</head>
<body>
<p>Move your cursor on this text.</p>
</body>
</html>
Difference between
mouseenter() and mouseover()
Unlike the mouseenter event, the
mouseover event triggers if a mouse pointer enters any child elements as well
as the selected element. The mouseenter event is only triggered when the mouse
pointer enters the selected element.
The mouseover event is occurred when
you put your mouse cursor over the selected element .or we can say that The mouseover event
occurs when the mouse pointer is over the selected element.The mouseover()
method triggers the mouseover event, or attaches a function to run when a
mouseover event occurs.
Syntax:
Step 1. $(selector).mouseover()
It triggers the mouseover event for
selected elements.
Step 2. $(selector).mouseover(function)
It adds a function to the mouseover
event.
Example-1
<!DOCTYPE html><html><head><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script>$(document).ready(function(){
$("p").hover(function(){ $(this).css("background-color", "red"); }, function(){ $(this).css("background-color", "green"); }); }); </script></head><body> <p>roll the mouse Arrow over this text.</p> </body></html> |
Example-2
<!DOCTYPE html>
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").mouseover(function(){ $("p").css("background-color", "blue"); }); $("p").mouseout(function(){ $("p").css("background-color", "green"); }); }); </script> </head> <body> <p>Move your cursor on this text.</p> </body> </html> |
Difference between
mouseenter() and mouseover()
Unlike the mouseenter event, the
mouseover event triggers if a mouse pointer enters any child elements as well
as the selected element. The mouseenter event is only triggered when the mouse
pointer enters the selected element.