Bug Tracker

Opened 14 years ago

Closed 13 years ago

#4867 closed bug (worksforme)

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:


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.

Change History (2)

comment:1 Changed 14 years ago by ricardobeat

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/

comment:2 Changed 13 years ago by dmethvin

Resolution: worksforme
Status: newclosed

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

Note: See TracTickets for help on using tickets.