[jQuery] Dynamically created input/button not responding to click event
I'm using javascript and Jquery to dynamically create an input button
and attempt to respond to a click even for that button. Unfortunately,
I can't get the click handler to work. I am creating the button like
this:
var removeButton = document.createElement("INPUT");
removeButton.type = "button";
removeButton.value = "Remove";
$(removeButton).addClass("removeButtonClass");
$("myDiv").append(removeButton);
My event handler looks like this:
$(function(){
$(".removeButtonClass").click(function() {
alert("handler worked");
})
})
In Firebug, I can see that the new input button is being successfully
created and the removeButtonClass is successfully being set, but when
I click the button the event handler is never called. What am I
missing?
Regards,
Jonathan