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

109
Visualizações
Can't get src of img (JS, Jquery)

I have some table.

            <table>                
            <tr>
                <td>1</td>
                <td><img src="uploads/0/58.gif"></td>
                <td>Name 1</td>
                <td>8</td>
            </tr>
            
            <tr>
                <td>2</td>
                <td><img src="uploads/0/25.gif"></td>
                <td>Name2</td>
                <td>5</td>
            </tr>
            </table>

Need to get src of all images from table. I'm doing some replaces in table, so var tbl = $('table').html();

After replaces, I need to get src-s: I really don't know how to write it, like $(tbl + 'tr').each.... So I write:

       $('table tr').each(function(index){ 
            let tds = $(this).find('td'); // get array td-s
            console.log(typeof(tds.html())) // Object
            console.log(tds[1]) // <td><img src="uploads/0/58.gif"></td>
            //$('img').src // error
            //$('img').getAttribute('src') // error,
            //$(this).find('img').src // error
            //ets...
        }); 

I try somethink like

or $(this).find('img) // == Object, i can't get src from

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You could use a more complete selector:

$('table td > img[src]').each(function(i, e) { }); 

Or for all images in the page with a source, it would look like this:

$('img[src]').each(function(i, e) { console.log(e.src); });

You might want to read up on CSS selectors :)

about 4 years ago · Santiago Trujillo Relatório

0

A very simple solution based on your tried examples is:

console.log(tds[1].firstChild.src);

To get result inside a loop:

$('table tr').each(function(index){ 
    console.log(tds[1].firstChild.src);
}); 
about 4 years ago · Santiago Trujillo 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