I am generating some buttons dynamically with dynamic ids. I wish to handle each button's click based on its id. But that's not working.
Following is my code:
var del_id = "del"+countPage+"-"+questionCount;
html+='<tr><td><input type="button" value="delete" id="'+del_id+'" /><td><input type="button" value="Copy" id="copy_id"/></tr>';
$("#"+del_id).click(function(){
alert("jkhkjh");
});
If I give static id instead of del_id, then it works. Where am I getting wrong? How do I solve this?
edited:solved
html+='<tr><td id="'+del_id+'"><input type="button" value="delete" id="'+del_id+'" /><td><input type="button" value="Copy" id="copy_id"/></tr>';
$(document).on("click", "#"+del_id, function(){
alert("jkhkjh");
});