I have the body of a table which is appended dynamically with ajax to the table element through a partial view in ASP.NET MVC. The partial view looks something like this...
@model IEnumerable<Plan>
@{
Layout = null;
}
@foreach (var plan in Model)
{
<tr>
<td>
<a href="#" class="jumpToMyPlans">@plan.Name</a>
</td>
</tr>
}
...and appended to the table element which is static in the main View...
<table id="myPlanTable">
</table>
I am trying to register an onclick event for each of these anchor elements (there are a lot currently), using the jQuery on()
function like this...
jQuery('#myPlanTable').on('click', 'tbody > tr:gt(0) > td > a.jumpToMyPlans', function () {
console.log('click');
});
...but the event refuses to fire. I've checked the DOM traversal in the browser console and it's definitely correct and returns the expected DOM set.