Alan Gutierrez wrote:
> * smeranda <[EMAIL PROTECTED]> [2006-11-21 16:55]:
>> However, the following code doesn't seem to
>> work on the dynamically created inputs (it does work for the static
>> text inputs). Any ideas what I'm doing wrong?
>>
>> $("input").change(indicateChange);
>>
>> function indicateChange(foo) {
>> alert("Item has changed Part II"); //continue with the required
>> function code.
>> }
>
> When you subsequently add elements to the document, you need to set
> the event handlers of the newly added elements.
>
> 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.
   }
}


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to