document.querySelector
will return
the first matching element in your document.
Assuming you want to update
the parent table of the button you clicked, you need to use the event object's
target
property:
<button onclick="calculateAndCheckDifference(event)">Calculate and Check</button>
const calculateAndCheckDifference = (e) => {
const table = e.target.closest("table");
...
};
However, your HTML as it stands is invalid. A
<table>
element cannot directly contain a
<button>
element. You need to wrap the button in
<tr>
and
<td>
tags to make it part of the table.