In my project, I need to check if the data-id-row values are equal to the data-id-row values of the checked table rows when the checkboxes are checked, return a value if it is equal, and a message if it is not equal. Show it.
this is my rows
<table>
<thead>
<tr>
<th>
<input type="checkbox" name="id[]">
</th>
<th>
first name
</th>
<th>
last name
</th>
</tr>
</thead>
<tbody>
<tr id="6">
<td><input type="checkbox"></td>
<td>hamid</td>
<td>hamidi</td>
</tr>
<tr id="7">
<td><input type="checkbox"></td>
<td>john</td>
<td>tyler</td>
</tr>
<tr id="8">
<td><input type="checkbox"></td>
<td>john</td>
<td>smith</td>
</tr>
</table>
How can I do that?
Try this, it will show you id's of all checked rows:
var trs= document.getElementsByTagName("tr");
for (var i = 0; i < trs.length; i++){
var tr = trs[i];
var checks = tr.getElementsByTagName("input");
if (checks.length > 0 && checks[0].checked)
alert(tr.id)
}