Skip to main content

Bug Tracker

Side navigation

#8573 closed bug (wontfix)

Opened March 21, 2011 02:50AM UTC

Closed March 21, 2011 03:25AM UTC

Using a jQuery selections function as an eventHandler confuses jQuery.

Reported by: kitsunde Owned by:
Priority: low Milestone: 1.next
Component: core Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

$("button").live("click", $("div").hide );

Results in an error:

Chrome 11 dev: #<HTMLButtonElement> has no method 'animate'

Firefox 3.6: this.animate is not a function

Indicating that the hide call is being executed on the "button" selection rather than the "div" selection.

Test case: http://jsfiddle.net/bLAvM/

I've also tested in jQuery 1.3.2 which gives the same problem, and I've attempted to use $("button").click instead of .live with the same exception.

Attachments (0)
Change History (1)

Changed March 21, 2011 03:25AM UTC by rwaldron comment:1

component: unfiledcore
priority: undecidedlow
resolution: → wontfix
status: newclosed

Replying to [ticket:8573 kitsunde]:

$("button").live("click", $("div").hide ); Results in an error: Chrome 11 dev: #<HTMLButtonElement> has no method 'animate' Firefox 3.6: this.animate is not a function Indicating that the hide call is being executed on the "button" selection rather than the "div" selection.

This happens because jQuery manages scope for callbacks in an unorthodox, yet consistent manner and all it sees you passing is a function definition, to which it will coerce the scope into whatever the calling selector set was.

Test case: http://jsfiddle.net/bLAvM/ I've also tested in jQuery 1.3.2 which gives the same problem, and I've attempted to use $("button").click instead of .live with the same exception.