I have a table and it has few values. I've assigned the highest value to a variable. Now I want to get the row index and column index of the cell that contain the value in the variable. How is it possible? I need to use jquery only.Any help is appreciated. Thnankyou.
Since you have not provided a reproducible code example,i have a code snippet for you,so you can modify it for your own needs,it gives you the cell index + row index of the highest number among all td cells,its not what you want but it gives you the logic you should follow (my opinion)
Keep in mind that indexes start at 0 (0,1,2,3...)
let allTd = []
document.querySelectorAll("td").forEach(td =>{
allTd.push(Number(td.innerText))
}) //create an array of all the numbers in td cells
let max = Math.max(...allTd) // find the highest number
document.querySelectorAll("td").forEach(td => {
if (Number(td.innerText) === max) {
console.log(`Row index : ${td.closest("tr").sectionRowIndex}`)
console.log(`Cell index : ${td.closest("td").cellIndex}`)
}
}) //compare highest number against all td cells then console.log row index and cell index of matching cell
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<table class="table table-bordered text-center">
<tbody>
<tr>
<td>6</td>
<td>23</td>
<td>13</td>
<td>17</td>
<td>44</td>
<td>12</td>
</tr>
<tr>
<td>3</td>
<td>56</td>
<td>67</td>
<td>32</td>
<td>20</td>
<td>12</td>
</tr>
<tr>
<td>15</td>
<td>62</td>
<td>13</td>
<td>9</td>
<td>77</td>
<td>12</td>
</tr>
</tbody>
</table>
</body>
</html>