jQuery mouseup()

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

jQuery mouseup()

The mouseup() method adds an event handler function to an HTML element. This function is executed, when the left mouse button is released after pressing mouse button on the HTML element.

The mouseup () event occurs when you release the pressed button of your mouse over a selected element. Once the mouseup() event is occurred it executes the mouseup() method attached with a function to run.

This event is generally used together with mousedown() event.

Syntax:

  1. $(selector).mouseup()  

It triggers the mouseup event for selected elements.

  1. $(selector).mouseup(function)  

It adds a function to the mouseup event.

Parameters of jQuery mouseup() event

Parameter Description
Function It is an optional parameter. It executes itself when the mouseup event is triggered.

Example of jQuery mouseup() event

Let's take an example to demonstrate jQuery mouseup() event.

  1. <!DOCTYPE html>    
  2. <html>    
  3. <head>    
  4. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>    
  5. <script>    
  6. $(document).ready(function(){    
  7.     $("#h1").mouseup(function(){    
  8.        $( "div" ).text( "Bye Bye... mouse up event triggered" ).show().fadeOut( 2000 );   
  9.     });    
  10. });    
  11. </script>    
  12. </head>    
  13. <body>    
  14. <h1 id="h1">Enter this heading.</h1>   
  15. <div></div>   
  16. </body>    
  17. </html>    

Test it Now

Output:

Enter this heading.

jQuery mouseup() event example 2

Let's see another example of jQuery mouseup() event.

  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
  5. <script>  
  6. $(document).ready(function(){  
  7.     $("p").mousedown(function(){  
  8.         $("p").css("background-color", "pink");  
  9.     });  
  10.     $("p").mouseup(function(){  
  11.         $("p").css("background-color", "yellowgreen");  
  12.     });  
  13. });  
  14. </script>  
  15. </head>  
  16. <body>  
  17. <p>Press down and release the mouse left button over this div element</p>  
  18. </body>  
  19. </html>  
  20.     

Test it Now

Output:

Press down and release the mouse left button over this div element