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.

Example1:

<!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>

Example2:

<!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").mouseup(function(){
$("p").css("background-color", "yellow");
});
});
</script>
</head>
<body>
<p>Press down the mouse left button over me</p>
</body>
</html>