Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




EVENTS - mouseleave()


The mouseleave() Event executes when a mouse pointer leaves an element.


Example :



<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://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script>
	  
      	<script>
      
			$('img').mouseleave( function() { 
            	$('p').text("Mouse pointer left the image")
            });
        
      	</script>      
  	</body>
</html>  


Output :



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.