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

98
Visualizações
Convert text inside td with http to a link

I want to detect all links for all td with item-description class; How to make this work if my string is both just the link and when the description is link with other text. Here is my code but it does not work!

<script>
var items = document.getElementsByClassName("item-description");
for (var i = 0; i < items.length; i++) {
      var text = items[i].innerText;
      var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
      text.replace(exp, "<a href='$1' target='_blank'>$1</a>");
    }
</script>

It doesn't work as it is, the text in are generated from form submissions. Basically if the text of td is something.com I want to make that into an a tag inside the td. I also want it to work when the text is the link text with other text. Sample: https:something.com other text here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First of all a TD is a cell in a table.

The cell can have different elements in it, including the tag which can make it clickable.

However, due to the nature of a table-cell, the height and width of a cell does not depend only on its contents but also on its neighboring tags which can cause the clickable area to cover only a part of the cell.

Hence to make the entire link clickable, you will have to bind a JavaScript (JS) click event on that td to make it to redirect to another page or whatever link you want.

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