I have some html appended using handlebars, but am unable to get the event from a hyperlink to fire:
JS - this code is called during document.ready.
$(".media-item a.meddelete").unbind("click");
$(".media-item a.meddelete").click(function (event) {
event.preventDefault();
var id = $(this).data("assetid");
alert(id);
});
HTML
<div class="media-item">
<p><a href="ImageManipulation.aspx">Edit</a></p>
<p><a href="#" class="meddelete">Delete</a></p>
</div>
I can't see what is wrong, any ideas?
document.ready()so the above html will not exist until after that. The 2 answers below, using 'on()' & delegation will fix this problem. If they do not work then there is something else wrong.