Bug Tracker

Ticket #1047 (closed bug: fixed)

Opened 8 years ago

Last modified 7 years ago

unbind(type) does not work as expected when `type` is not bound to the jQuery

Reported by: humbleice Owned by:
Priority: minor Milestone: 1.1.3
Component: event Version: 1.1.1
Keywords: unbind Cc:
Blocking: Blocked by:

Description

The unbind function will remove all events attached to a jQuery object if it cannot find an event of the type given in the unbind params.

For example: The following code will create a div element with an attached click event. On click, an alert should pop-up and unbind any mouseup events to the jQuery object. Because there is no onMouseUp event attached to the object, the unbind call will unattach the onClick event preventing the alert from appearing when the div element is clicked again.

$("<div id='hi'>Div with broken unbind function</div>")
  .click(
    function() {
      alert('clicky');
      $(this).unbind("mouseup");
    })
  .insertAfter("head");

The code below is a duplicated of the code above but the created Div element has an attached onMouseUp event. In this case, unbind("mouseup") works as expected and the onClick alert will appear anytime the user clicks the Div element (and the mouseup alert will be removed after the first click)

$("<div id='hi'>Div when unbind works as expected</div>")
  .click(
    function() {
      alert('clicky');
      $(this).unbind("mouseup");
    })
  .mouseup(
    function() {
      alert("mouseup");
    })
  .insertAfter("head");

FireFox 2.0.0.2 (fix needed for unbind related plugin)

Change History

comment:1 Changed 8 years ago by brandon

  • Status changed from new to closed
  • Resolution set to fixed

This has been fixed in Rev 1471.

Note: See TracTickets for help on using tickets.