#953 closed bug (worksforme)
Binding click handler fails on newly created anchor
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | major | Milestone: | |
Component: | core | Version: | |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Fails in jQuery 1.1:
$('<a href="#">I am here</a>').prependTo('#test').bind('click', function() { return false; });
Workaround:
$('#test').prepend('<a href="#">I am here</a>').find('a').bind('click', function() { return false; });
Change History (4)
comment:1 Changed 16 years ago by
comment:2 Changed 16 years ago by
Also, the first example would only work if the result was a single node. If it is multiple nodes, the prependTo will clone the nodes and append the clones to #test; the event will bind to the (orphaned) original nodes.
As far as I can see with that example it *should* be a single node, but perhaps this isn't the real code. Also, binding before prependTo might fix it, but that causes a small memory leak in IE6 as I recall.
comment:3 Changed 16 years ago by
To clarify, I meant the destination (in this case, #test) is multiple nodes.
comment:4 Changed 16 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Version: | 1.1 |
Ok, it sounds like this was possibly an unrelated bug. (Klaus, correct me if I'm wrong)
Note: See
TracTickets for help on using
tickets.
I can't confirm this - I just pasted this into the jQuery site, ran it, and clicked the link - worked just like you'd expect it to. Do you think you could provide a more-complete example of where it fails?