Skip to main content

Bug Tracker

Side navigation

#1047 closed bug (fixed)

Opened March 14, 2007 04:52PM UTC

Closed March 22, 2007 12:40PM UTC

Last modified June 20, 2007 12:50AM UTC

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:
Blocked by: Blocking:
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)

Attachments (0)
Change History (1)

Changed March 22, 2007 12:40PM UTC by brandon comment:1

resolution: → fixed
status: newclosed

This has been fixed in Rev 1471.