Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda