I noticed somewhat odd behavior when using .click() on newly created
elements.  If the .click() is assigned prior to the element being
attached to the DOM, the element behaves as if there is no event bound
to it.

var removeLink = $("<a href='#'>Remove</a>").click(function()
{alert('hello');});
$(".portlet .handle").append(removeLink); 

Tested this in both FF 1.5 and IE6 and the event appears to have never
been bound to the element.

However, this works fine:

var removeLink = $("<a href='#'>Remove</a>");
$(".portlet .handle").append(removeLink); 
$(".portlet .handle a").click(function() {alert('hello');});;

Is this expected behavior?  It is not a big deal at all though it did
cost me a bit of time earlier this morning try to figure why things
weren't working.  If this is expected behavior a short note/warning in
event docs would be nice :)

Regards,
-scott

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to