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

189
Visualizações
how to find a td by index in jquery

how can i change the inner html by getting element by index
i want to change the content of cells according to their index values

<table>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
</table>
function LFLS() {
    // LFLS => load from local Storage
    for (i = 0; i < localStorage.length; i++) {
        key = localStorage.key(i);//it return values like ("1,2","2,5", etc.)
        console.log(key)
        row = key.split(",")[0];
        col = key.split(",")[1];
//how to get the cell by row and col
}
}
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

As Sakil said you can use eq(). Try this:

function LFLS() {
    // load from local Storage
    for (i = 0; i < localStorage.length; i++) {
        key = localStorage.key(i);
        row = key.split(",")[0];
        col = key.split(",")[1];
        // how to get the cell by row and col
        $("table tr").eq(row).children().eq(col).html('NEW VALUE')
    }
}

about 4 years ago · Juan Pablo Isaza Relatório

0

I believe you need the following snippets.

Before your for loop

const rows = $("table tr");

After you obtain row & col variables

const cellToUpdate = rows[row].children[col];

Alternatively, if you're looking to programatically loop through the table you could use the following snippet.

<script type="text/javascript">

    const rows = $("table tr");
    for( i = 0; i < rows.length; i++ ) {
        const currRow = rows[i];
        const rowChildren = currRow.children;
        for( n = 0; n < rowChildren.length; n++ ) {
            const cell = rowChildren[n];
            cell.innerHTML = "My new data for row: " + i + " in cell " + n;
        }
    }
</script>
about 4 years ago · Juan Pablo Isaza Relatório

0

Is something on the lines of below not going to work for you for some reason?

$("table tr:nth-of-type([your-row])).eq([your-col]).html([your_content]);

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