Skip to main content

Bug Tracker

Side navigation

#953 closed bug (worksforme)

Opened February 13, 2007 05:57PM UTC

Closed February 19, 2007 04:56AM UTC

Last modified June 20, 2007 01:54AM UTC

Binding click handler fails on newly created anchor

Reported by: klaus.hartl@stilbuer 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; });
Attachments (0)
Change History (4)

Changed February 13, 2007 06:07PM UTC by john comment:1

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?

Changed February 13, 2007 06:13PM UTC by Dave comment:2

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.

Changed February 13, 2007 06:15PM UTC by Dave comment:3

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

Changed February 19, 2007 04:56AM UTC by john comment:4

resolution: → worksforme
status: newclosed
version: 1.1

Ok, it sounds like this was possibly an unrelated bug. (Klaus, correct me if I'm wrong)