$('#A').click(function () {
$('#A1').prepend('<div class="AcL" id=' + i + '>Hello<span class="RmMe" id="' + i + '" style="margin-left:20px; cursor:pointer;">X</span></div>');
i++;
});
$('.RmMe').click(function () {
alert("OK");
});
<div id="A1"></div>
Any idea why the click is not working?
You need to use
.delegate()or.live()because you are attempting to bind a handler to an element that does not yet exist.Try that.
EDIT:
However, should you be using jQuery 1.7+, the
.onmethod is the preferred approach: See post from xdazzGood luck!