Quite expected behavior :-)
You should always use jQuery( htmlSnippet ) and attach it to the dom as soon
as possible.
This also works fine, and is a typical chain:
var removeLink = $(" # Remove ")
.appendTo( ".portlet .handle" )
.click( function() { alert( 'hello' ); } );
--Andrea
Weaver, Scott-2 wrote:
>
> 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 = $(" # Remove ").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 = $(" # Remove ");
> $(".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
> [email protected]
> http://jquery.com/discuss/
>
>
--
View this message in context:
http://www.nabble.com/Question-about-binding-.click%28%29-%28and-other-events%29-to-parentless-elements-tf3327728.html#a9253176
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/