.mouseup() JQ Home  <<  Events  <<  .mouseup()

Mouseup event handler.

Description

The .mouseup() method is used to bind an event handler to The JavaScript mouseup event or trigger that event on the specified element.

  • The mouseup event is sent to an element when the mouse pointer is over the element and any mouse button is released.
  • For 'drag' and 'drop' operations it is generally preferable to use the .click() method for deciding when a 'drop' has ended.

Syntax

Signature Description
.mouseup( )Trigger the mouseup JavaScript event on the specified element.
.mouseup( handler(eventObject) )Bind an event handler to the mouseup JavaScript event.
.mouseup( [eventData ,] handler(eventObject) )Bind an event handler to the mouseup JavaScript event, optionally passing an object of data.

Parameters

Parameter Description Type
handler( eventObject )A function to execute each time the event is triggered.Function
eventDataAn object of data to pass to the event handler.Anything

Return

A jQuery object.

.mouseup( ) Example  Events  <<  Top

Trigger the mouseup JavaScript event on the specified element.

  • This signature is a shortcut for .trigger('mouseup').

In the example below we show a new message in the 'div' element with an id of 'div3' every time the radio button for fish pie is clicked on with the mouse and the mouse button released, or the division itself is clicked on with the mouse and the mouse button released.

When the radio button is pushed, or the division itself is clicked on we trigger off the mouseup JavaScript event on the 'div3'. This then fires off the $('#div3').mouseup(function(){}) code which outputs the message.

Pie Survey

Which pie do you prefer?:

Select a pie shape: 

div1. Some initial text.



$(function(){
  $('#div1').mouseup(function () {
    $('#div1').append('<code>mouseup</code> JavaScript event triggered.
                       You like Fish Pie!!<br>');
  });

  $('#fish').click(function() {
    $('#div1').mouseup();
  });
});




.mouseup( handler(eventObject) ) Example  Events  <<  Top

Bind an event handler to the mouseup JavaScript event.

  • This signature is a shortcut for .on('mouseup', handler).

In the example below we show a new message in the 'p' element with an id of 'scrollspan1' each time the 'div' element with an id of 'div2' below is hovered over and a mouse button released, the mouse button does not have to be over the element when it was originally pressed.

When the mouse button is released, the mouseup JavaScript event fires off the addText(event) mothod which outputs a message.

What we are doing here is passing across the event object to the function addText(event)method. The data we specify gets tagged onto the event.data property.



$(function(){
  $('#div2').mouseup(addText);

  function addText(event) {
    $('#scrollspan1').append('mouseup 1 **JavaScript event triggered**<br>');
  }
});



div2. Release Mouse button Here.

We will show a message here.

.mouseup( [eventData ,] handler(eventObject) ) Example  Events  <<  Top

Bind an event handler to the mouseup JavaScript event, optionally passing an object of data.

  • This signature is a shortcut for .on('mouseup', handler).

In the example below we show a new message in the 'p' element with an id of 'scrollspan2' each time the 'div' element with an id of 'div3' below is hovered over and a mouse button released, the mouse button does not have to be over the element when it was originally pressed.

When the mouse button is released, the mouseup JavaScript event fires off the $('#div4').mouseup({ param1: '#scrollspan2', param2: 'mouseup', param3: '**JavaScript event triggered** ' }, addText2); code.

What we are doing here is passing across the event object to the function addText2(event). The map we specify, in our case { param1: '#scrollspan2', param2: 'mouseup', param3: '**JavaScript event triggered** ' } gets tagged onto the event.data property. We then access this parameter in the function via event.data.param and use it as part of the appended data.



$(function(){
  $('#div3').mouseup({ param1: '#scrollspan2', param2: 'mouseup 2 ', 
                       param3: '**JavaScript event triggered**  ' }, addText2);

  function addText2(event) {
    $(event.data.param1).append( event.data.param2 + ''<code>' + event.data.param3+ ''</code>');
  }
});



div3. Release Mouse button Here.

We will show a message here.


Related Tutorials

jQuery Advanced Tutorials - Lesson 2 - Keyboard & Mouse Events