tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

mouseup()

.mouseup( handler(eventObject) )

Returns: jQuery

Description: Bind an event handler to the "mouseup" JavaScript event, or trigger that event on an element.

.mouseup( handler(eventObject) )

version added: 1.0
handler(eventObject)
A function to execute each time the event is triggered.

.mouseup( )

version added: 1.0

.mouseup( [ eventData ], handler(eventObject) )

version added: 1.4.3
eventData
A map of data that will be passed to the event handler.
handler(eventObject)
A function to execute each time the event is triggered.

This method is a shortcut for .bind('mouseup', handler) in the first variation, and .trigger('mouseup') in the second.

The mouseup event is sent to an element when the mouse pointer is over the element, and the mouse button is released. Any HTML element can receive this event.

For example, consider the HTML:

<div id="target">
  Click here
</div>
<div id="other">
  Trigger the handler
</div>
<div id="log"></div>
The output of the code above will be:
Move here
Trigger the handler

The event handler can be bound to any <div>:

$('#target').mouseup(function() {
  alert('Handler for .mouseup() called.');
});

Now if we click on this element, the alert is displayed:

Handler for .mouseup() called.

We can also trigger the event when a different element is clicked:

$('#other').click(function() {
  $('#target').mouseup();
});

After this code executes, clicks on Trigger the handler will also alert the message.

If the user clicks outside an element, drags onto it, and releases the button, this is still counted as a mouseup event. This sequence of actions is not treated as a button press in most user interfaces, so it is usually better to use the click event unless we know that the mouseup event is preferable for a particular situation.

Examples

Show texts when mouseup and mousedown event triggering.
 $("p").mouseup(function(){
   $(this).append('Mouse up.');
    }).mousedown(function(){
   $(this).append('Mouse down.');
    });
The output of the code above will be:

Example - Full source:

<!DOCTYPE html>
<html>
<head>

<script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script type="text/javascript" language="javascript">

  $(document).ready(function(){
    
 $("p").mouseup(function(){
   $(this).append('<span style="color:#F00;">Mouse up.</span>');
    }).mousedown(function(){
   $(this).append('<span style="color:#00F;">Mouse down.</span>');
    });

  });
  </script>

  
</head>
<body>
  <p>Press mouse and release here.</p>

</body>
</html>
Was this information helpful?
   

Comments