Bug Tracker

Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#953 closed bug (worksforme)

Binding click handler fails on newly created anchor

Reported by: klaus.hartl@… 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 14 years ago by john

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?

comment:2 Changed 14 years ago by Dave

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 14 years ago by Dave

To clarify, I meant the destination (in this case, #test) is multiple nodes.

comment:4 Changed 14 years ago by john

Resolution: worksforme
Status: newclosed
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.