CodesJava

Easy learning with example program codes

jQuery mouseup()


The jQuery mouseup() method is used to attach a function to run when a mouseup event occurs i.e, when the left button of the mouse is released after pressing on the selected element.

Syntax:

To trigger the mouseup event for selected elements.

$(selector).mouseup()  

To add a function to the mouseup event.

$(selector).mouseup(function)   

Function:

  • It is an optional parameter.
  • The function parameter specifies the function to run when the event occurs.

 

Example 1

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  
<script>    
$(document).ready(function(){    
	$("#h1").mouseup(function(){    
   	$( "div" ).text( "Mouse up event triggered" ).show().fadeOut( 2000 );   
	});    
});    
</script>    
</head>    
<body>    
<h1 id="h1">Click Me.</h1>   
<div></div>   
</body>    
</html>

Try it

JS Bin on jsbin.com

Example 2

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
	$("p").mousedown(function(){  
    	$("p").css("background-color", "red");  
	});  
	$("p").mouseup(function(){  
    	$("p").css("background-color", "yellow");  
	});  
});  
</script>  
</head>  
<body>  
<p>Press down the mouse left button over me</p>  
</body>  
</html>

Try it

JS Bin on jsbin.com

Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki