<table>
<thead><tr>id</tr><tr>delete</tr></thead>
<td>
{% for id in ids %}
<tr>{{id}}</tr>
<tr><button id="delete_btn"></button></tr>
{% endfor %}
</td>
</table>
<table>
<thead><th>id</th><th>delete</th></thead>
<tr>
{% for id in ids %}
<td>{{id}}</td>
<td><button>x</button></td>
{% endfor %}
</tr>
</table>
table.addEventListener('click', function(evt){
const btn = evt.target.closest('button');
if (btn) {
const id = btn.parentNode.previousElementSibling.textContent;
console.log({id});
}
});