> > It would work to rerun your $("input").change(indicateChange) method
> > after you've added new elements. Come back if that's too slow.
>
> Another nice way to do this is to take full advantage of event bubbling.
> You
> attach the event listener to the body element instead of the individual
> inputs, and thus it keeps working even for dynamically created elements.
> And
> in addition you only need one event listener instead of several:
>
> Following code untested but should work.
>
> $("body").change(indicateChange($(event.target)));
>
> function indicateChange(foo) {
> if(foo.is('input'))
> {
> alert("Item with name '"+foo.name()+"' has changed...");
> // other function code.
> }
> }
You should also consider to attach the listener to the nearest parent instead
of the body, eg. for input element their form element. That prevent to much
bubbling. Anyway, using event delegation is a very good idea, jQuery provides
the right target element for you (it normalizes event.srcElement for IE and
text nodes in Safari).
--
Jörn Zaefferer
http://bassistance.de
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/