Modify ↓
Ticket #8573 (closed bug: wontfix)
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: | ||
| Blocking: | Blocked by: |
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.
Change History
comment:1 in reply to: ↑ description Changed 2 years ago by rwaldron
- Priority changed from undecided to low
- Resolution set to wontfix
- Status changed from new to closed
- Component changed from unfiled to core
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

Replying to kitsunde:
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.