jQuery mouseover() Method
You are Here:
jQuery mouseover() Method
The jQuery mouseover()
method is used for the following 2 purpose
- To run a callback when a mouse is over a specified element.
- To trigger the mouseover event of a specified element.
Run a Callback
In the following example, we will run a callback function when a mouse is over 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 mouseover() Method</h1>
<p>Try to touch me.</p>
<script>
$(document).ready(function(){
$("p").mouseover(function(e){
alert("You are over the paragraph.");
});
});
</script>
</body>
</html>
Syntax
$(selector).mouseover(callback);
Parameter Values
Value | Type | Explanation |
---|---|---|
callback | Optional | Specifies a function to be called once user mouse is over the element. |
Trigger a mouseover Event
In the following example, we will trigger a mouseover 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 mouseover() Method</h1>
<p>Try to touch me.</p>
<button>Trigger mouseover </button>
<script>
$(document).ready(function(){
$("p").mouseover(function(e){
alert("You are over the paragraph.");
});
$("button").click(function(e){
$("p").mouseover();
});
});
</script>
</body>
</html>
mouseover() vs mouseenter()
Check out the difference between mouseover() vs mouseenter() in jquery.
Reminder
Hi Developers, we almost covered 99.5% of jQuery Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in jQuery.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.