Skip to main content

Bug Tracker

Side navigation

#4867 closed bug (worksforme)

Opened July 08, 2009 01:04AM UTC

Closed November 18, 2009 02:55AM UTC

binding "click" event to html()'ed content element causes spurious events

Reported by: dennisj Owned by: brandon
Priority: major Milestone: 1.4
Component: event Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:
Description

A self-contained minimized test case of the problem can be found here:

http://pastebin.com/f6990228d

This page displays the text "STATE1" and clicking on it changes it to "STATE2". Clicking on that however switches the text back to "STATE1" (which is correct) and then immediately back to "STATE2" which it shouldn't.

The problem is that after initState1() is called a click event is occuring that shouldn't which causes the immediate call of initState2() again.

Uncommenting the commented javascript line and commenting the one above it shows how the code should behave but uses the static id of the outer div rather than the class of the code inserted with the html() function.

What I would expect is to get the correct behavior in both cases.

Attachments (0)
Change History (2)

Changed July 14, 2009 06:29AM UTC by ricardobeat comment:1

It's an issue of logic.

After a click, by the time initState1 finishes and the event bubbles up, a new event handler has been added to the parent (which is then triggered by the same event).

Discussion at http://groups.google.com/group/jquery-dev/browse_thread/thread/9a236233eb83ee36

Plain Javascript testcase showing the same issue: http://jsbin.com/eqoti/

Changed November 18, 2009 02:55AM UTC by dmethvin comment:2

resolution: → worksforme
status: newclosed

I think this example is convoluted, but working as it should.