I have the following LINK in HTML razor:
<a class="btnOpen" data-id="@item.Id">
Link
</a>
And the next Script
$('.btnOpen').click(function () {
alert("The Link was clicked");
});
All in INDEX.HTML, it's works fine
I have to change the view using AJAX, and re-create the Link with the following code:
$.ajax({
type: "post",
url: "/Controller/Action",
data: jQuery.param({ cod: cod }),
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
success: function (newId) {
$('body').append(" <a class='btnOpen' data-id='"+newId+"'> Link </a> ");
}
});
This show the new Link but does not call to .btnOpen Function. I dont know why and which is the scope of the click event when using Ajax