In my HTML page I am dynamically adding some elements on some action. I have assigned certain classes to these elements so that suitable events should get fired whenever these controls are used. I have done it as following:
$(document).ready(function(){
$("#btnAddMicroElement").click(function(event,microelement){
microelement=microelement.replace("'","'");
$("#divMicroElements").append("<div class='clsdivmicroelement' style='border-bottom: 2px black solid;'><div><label>Microelement</label><input type='text' class='clstxtmicroelement' value='"+microelement+"'/><input type='button' class='clsbtnmicroelmentadd' value='Add'/></div><div><input type='button' value='Add All' class='clsbtnmicroelementaddall'/></div></div>");
return false;
});
$(".clsbtnmicroelementadd").click(function(){
alert("its working");
});
});
In the above given code I am adding some elements to the page on click event of btnAddMicroElement
, one of which is an input text with class clsbtnmicroelementadd
. I want some action to be performed when this button is clicked. For this I have written click event handler for this class. But it is not getting executed. Is it even allowed to write events for dynamically created elements like this? Please help me to correct my code to get it working.