[jQuery] Question about binding .click() (and other events) to parentless elements

2007-03-01 Thread Weaver, Scott
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');});

Re: [jQuery] Question about binding .click() (and other events) to parentless elements

2007-03-01 Thread Abel Tamayo
This won't help your problem at all, but I would also like to add that I've found exceptions in IE6 when adding css attributes to an element that hasn't still been attached to the DOM, i.e: var elem = $(li).css(color, red); I don't know if these problems are still present in the new release

Re: [jQuery] Question about binding .click() (and other events) to parentless elements

2007-03-01 Thread Andrea Ercolino
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,