I am trying to get the parent id when clicked with jquery.
My django template is as follows:
<table id="archive-table" class="table table-hover table-vcenter">
<thead>
<tr>
<th>Make and model</th>
<th>First registration</th>
</tr>
</thead>
<tbody>
{% for calculation in calculations %}
<tr data-archive-row class="archive-row" data-calculation-id={{ calculation.id }}>
<td>{{ calculation.first_registration }}</td>
<td>{{ calculation.body }}</td>
</tr>
{% endfor %}
</tbody>
</table>
And my js looks like this:
<script>
$(document).ready(function () {
$('#archive-table').on('click', '[data-archive-row]', function (e) {
var calculation_id = e.target.dataset['calculationId'];
alert(calculation_id)
})
});
</script>
How can I get a dataset['calculationId']parent, regardless of whether I clicked on a child.
With my code, I get undefined in the message. But if, for example, I add tddata-calculation-id={{ calculation.id }} to one , and if I then click on it, then I will get the correct identifier.
Is there a way to get the identifier from the parent, regardless of whether it clicked on the child or on the parent?
source
share