jquery click commands on dynamic html

jquery click commands on dynamic html

hi.

i am dynamically adding html to my page using the .html(...) function which is triggered based on some user action.

i have also defined a click function specific to some id tags that is in the dynamic html. when i generate the dynamic html and call the click function, nothing happens (aka, the click function is not getting called...) what could be the problem?

i have attached the code below:

following html code called upon a user action, which adds a button on the page with id = addTask:

.html("<input name='add' type='button' value='Add' id='addTask'>")


when the user clicks on this button, the following function should be called, but it ISNT...and this is the issue:

$('#addTask').click(function() {
   alert("adding...");
}


when i click the add button, i don't get an alert...