You're binding the second event to the inner element - when you click
it, the event bubbles up to #blk_1, so *both* handlers are triggered.
Try this: http://pastebin.com/m44c1cffd

Anyway, the way you're doing it doesn't make sense. You should just
use live() for the inserted elements and return false/e.preventDefault
() to stop bubbling.

On Jul 8, 8:12 am, Dennis Jacobfeuerborn <djacobfeuerb...@gmail.com>
wrote:
> live() version:http://pastebin.com/f5781ee8b
>
> The live() version works...as long as you don't introduce a second
> block.
>
> In this example "blk_1" and "blk_2" can be independently between
> STATE1 and STATE2 as long as you make sure that the last click
> switches a block to STATE1 before you modify the other block. If you
> switch a block to STATE2 and then modify the other block then the
> initial block can no longer be switched back and forth. Apparently the
> die() removes the handler from both blocks despite only adressing the
> "own" block using a selector like e.g. "#blk_1 .blk_type".
>
> Again if you replace the "'#'+block_id+' .blk_type'" bits by
> "'#'+block_id" so that the handler is no longer attached to the
> dynamically inserted html but the outer static div around it the
> example starts working as it should.
>
> This is problematic since what I'm actually trying to do is to get
> html code from the server via ajax that represents a panel with
> buttons and I then need to attach a click handler to these buttons
> which will then again send an ajax request to the server.
>
> I have no idea how to implement something like this if I cannot insert
> html with html() and then attach event handler to the inserted
> elements.
>
> On Jul 8, 5:06 am, Ralph Whitbeck <ralph.whitb...@gmail.com> wrote:
>
> > Have you tried using live instead of bind?
>
> >http://docs.jquery.com/Events/live#typefn
>
> > On Tue, Jul 7, 2009 at 9:15 PM, Dennis Jacobfeuerborn <
>
> > djacobfeuerb...@gmail.com> wrote:
>
> > >http://pastebin.com/f6990228d
>
> > > In this code clicking on the text should change it between "STATE1"
> > > and "STATE2" but doesn't. It actually does switch to STATE1 again but
> > > due to a spurious "click" event immediately switches back to STATE2 so
> > > that the switch can't be really seen. Uncommenting the commented
> > > javascript line and commenting the one above it no longer uses html()
> > > and show the correct behavior.
>
> > > Is this a bug or am I doing something fundamentally wrong here?
>
> > > Regards,
> > >  Dennis
>
> > > PS: I filed a bug here:http://dev.jquery.com/ticket/4867
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to