After the user creates a div with a button click I'd like to be able to click on that div and change its color. I'm wondering why this is not possible. It works if the div is hard coded in but not after it is dynamically created. Also, how do I make it work?
$("#addDiv").click(function() {
var div = '<div id="clickMe" style="width:200px; height:200px; background:blue;"></div>';
$("#container").html(div);
});
$("#clickMe").click(function() {
$(this).css("background", "red");
});