0

I have a form where i attach the OnChange method like

$(document).ready(function () {
    $('#fieldId').change(function () {
    ...
   }
}

But i have the case when i add a new record with the Id "fieldId" from a function as

function addTeamMember() {
var newItem= "<input  id='fieldId' type='text'>"
$("#other").append(newItem);
...
}

But the Change is not fired when i change the newly added field. Can somebody help me with an idea?

Thanks.

Jake Manet
  • 1,174
  • 3
  • 15
  • 26

1 Answers1

2

Change the onchange event listener to:

$('body').on('change', '#fieldId', function () {
  // ...
}

you can replace the 'body' with any container that is wrapping the dynamically added DOM element. This way, you delegating the event to existing or not existing yet elements.

Jumpa
  • 878
  • 1
  • 8
  • 12