Suppose that i have a table that is populated with a razor @foreach loop.
For each row, I have a delete button, which looks something like this:
.....
<tr>
<div style="cursor: pointer; display: inline-block; margin-left:5px" id="deleteEntity" data-Id="@Student.Id" data-Name="@Student.Name" data-Age="@Student.Age">
<i class="far fa-trash-alt"></i>
<span style="color:#bfbfbf">Delete</span>
</div>
</tr>
I want to have a jQuery function, that is capable of fetching the data attributes from my #deleteEntity div. Therefore I have done something along the lines of this:
$('#deleteEntity').on("click", function (event) {
var button = $(event.target);
var Id = button.data('Id')
var Name = button.data('Name')
var Age = button.data('Age')
debugger;
});
However based on what I have done above, all of my values are Undefined.
- Therefore, how do I correct this, so that I get the values that are specific to this delete button in my table?