The mouseleave() Event executes when a mouse pointer leaves an element.
<html>
<head>
<title> My First Programme </title>
</head>
<body>
<h1> JQuery </h1>
<p class = "para1"> First Paragraph </p>
<img src = "/myImage.png" alt = "Bring the mouse pointer here"/>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"> </script>
<script>
$('img').mouseleave( function() {
$('p').text("Mouse pointer left the image")
});
</script>
</body>
</html>
So, if you look at the above code, we have a <p> element,
<p class = "para1"> First Paragraph </p>
And we have an image,
<img src = "/myImage.png" alt = "Bring the mouse pointer here"/>
Now, if we take a look at the JQuery statement,
$('img').mouseleave( function() {
$('p').text("Mouse pointer left the image")
});At first we locate the image,
$('img')Then we use the mouseleave() event,
$('img').mouseleave(...)And put the function inside mouseleave() event to change the contents of <p> element.
$('img').mouseleave( function() {
$('p').text("Mouse pointer left the image")
});And the function,
function() {
$('p').text("Mouse pointer left the image")
}Changes the content of <p> with the text,
'Mouse pointer left the image'
When the mouse pointer leaves the Image.