Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
row index and column index of a value in JQuery

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!