Spec-Zone.ru › jQuery

mouseup event

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

Contents:

  • .on( "mouseup" [, eventData ], handler )
    • .on( "mouseup" [, eventData ], handler )
  • .trigger( "mouseup" )
    • .trigger( "mouseup" )

.on( "mouseup" [, eventData ], handler )Returns: jQuery

Description: Bind an event handler to the "mouseup" event.

  • version added: 1.7.on( "mouseup" [, eventData ], handler )

    • "mouseup"
      Type: string
      The string "mouseup".
    • eventData
      Type: Anything
      An object containing data that will be passed to the event handler.
    • handler
      Type: Function( Event eventObject )
      A function to execute each time the event is triggered.

This page describes the mouseup event. For the deprecated .mouseup() method, see .mouseup().

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>
Figure 1 - Illustration of the rendered HTML

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

$( "#target" ).on( "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" ).on( "click", function() {
  $( "#target" ).trigger( "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.

Example:

Show texts when mouseup and mousedown event triggering.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>on demo</title>
  <script src="https://code.jquery.com/jquery-4.0.0.js"></script>
</head>
<body>
 
<p>Press mouse and release here.</p>
 
<script>
$( "p" )
  .on( "mouseup", function() {
    $( this ).append( "<span style='color:#f00;'>Mouse up.</span>" );
  } )
  .on( "mousedown", function() {
    $( this ).append( "<span style='color:#00f;'>Mouse down.</span>" );
  } );
</script>
 
</body>
</html>

Demo:

.trigger( "mouseup" )Returns: jQuery

Description: Trigger the "mouseup" event on an element.

  • version added: 1.0.trigger( "mouseup" )

    • "mouseup"
      Type: string
      The string "mouseup".

See the description for .on( "mouseup", ... ).

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/mouseup

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API