Skip to main content

Bug Tracker

Side navigation

#7520 closed bug (worksforme)

Opened November 15, 2010 10:54AM UTC

Closed April 17, 2011 12:23AM UTC

Last modified March 15, 2012 12:42PM UTC

$(document).unbind('click') seems to clear live click callbacks

Reported by: art.orlov Owned by:
Priority: low Milestone:
Component: event Version: 1.4.4
Keywords: neededdocs Cc:
Blocked by: Blocking:
Description

It seems that doing $(document).unbind('click') removes not only all click handlers attached to document node but also live click handlers like:

$('a[data-method]:not([data-remote])').live('click', ...)

The same stuff with $('body').delegate() because it uses the same live technique.

It seems clear that $(document).unbind('click') should only clear callbacks attached using bind function. And die is designed for live callbacks.

Attachments (0)
Change History (11)

Changed November 15, 2010 05:08PM UTC by jitter comment:1

possible test case

Changed November 15, 2010 05:20PM UTC by boushley comment:2

Dang jitter beat me to it! Here's my fiddle anyways http://jsfiddle.net/boushley/y5fVv/

Changed November 15, 2010 07:21PM UTC by jitter comment:3

Well I like yours better anyway :D

Changed November 16, 2010 10:25AM UTC by Neeraj Singh comment:4

Not sure if it is valid but I attempted to create a failing test. https://github.com/neerajdotname/jquery/commit/9cce81f0c19ed3506f0d955716f280b2e60d2fcc

Changed November 16, 2010 11:01AM UTC by art.orlov comment:5

Replying to [comment:4 Neeraj Singh]:

Not sure if it is valid but I attempted to create a failing test. https://github.com/neerajdotname/jquery/commit/9cce81f0c19ed3506f0d955716f280b2e60d2fcc

Seems to be absolutely correct testcase, that's what we did in our code. Thanks for writing it.

Going spend time next time on writing testcases instead of text description :)

Changed November 16, 2010 05:42PM UTC by rwaldron comment:6

component: unfiledevent
keywords: → needsreview
milestone: 1.5
priority: undecidedlow
status: newopen

Confirmed - but it the behaviour is consistent all the way back to 1.2.6

http://jsfiddle.net/rwaldron/y5fVv/4/

This is a little clearer, and further reduced. The test result is laid out.

Changed April 01, 2011 03:01AM UTC by dmethvin comment:7

Given the implementation this makes sense; there is a special "live" event attached to the delegate elements (document for the .live() case but any element for .delegate()) and if you unbind all events from an element it, well, unbinds ALL events.

Should we just document it works this way, or somehow segregate the events better? I'd prefer to see it documented because it seems like a lot of work to keep them apart. Long term I think there could be some benefit to unifying our event APIs similar to what Prototype did with .on("event", "selector", data, fn) and if we start treating them differently that will make less sense.

Changed April 01, 2011 12:56PM UTC by art.orlov comment:8

I see that such behavior is not transparent to user. And i guess most of them don't know how .live() event handler works. I'd prefer the way of separating delegated and direct event handlers. Like the way native event handlers (attached via .addEventListener etc.) are separated from ones handled by jQuery.

Changed April 17, 2011 12:23AM UTC by john comment:9

keywords: needsreviewneedsdocs
resolution: → worksforme
status: openclosed

I think that this is "OK" (in that it's the expected result - delegate and live both are attaching click handlers to the document). I don't think we should try to obscure this, that might end up creating unexpected results. I'm going to flag this as "needsdocs" so that we can go back later and improve the documentation here.

Changed May 16, 2011 04:55AM UTC by addyosmani comment:10

Initial docs update: http://api.jquery.com/unbind/. Could be improved.

Changed June 08, 2011 05:40AM UTC by addyosmani comment:11

keywords: needsdocsneededdocs