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

136
Visualizações
Parse and modify an html string in JavaScript

I have this string HTML. it can have many href attributes.

"<h4> TITLE </h4> <p>test</p> 
<a\r\n class=\"link\"\r\n target=\"_blank\" \r\n href=\"https://test.com\">\r\n LABEL HERE </a>.\r\n </p>\r\n     
<a\r\n class=\"link\"\r\n \r\n href=\"https://test2.com\">\r\n LABEL HERE 2 </a>.\r\n </p>\r\n" 

I need to loop to every a href and modify it and return it to something like this below: add text in the label. and add target="_blank" in the href attribute if it's not there yet. Would really appreciate the help. tried many things but couldn't get this to work.

"<h4> TITLE </h4> <p>test</p>  
 <a\r\n class=\"link\"\r\n \r\n target=\"_blank\" href=\"https://test.com\">\r\n LABEL HERE (ADD TEXT HERE)</a>.\r\n </p>
 <a\r\n class=\"link\"\r\n \r\n target=\"_blank\" href=\"https://test2.com\">\r\n LABEL HERE2 (ADD TEXT HERE)</a>.\r\n </p>" 

EDIT: tried this code but im getting the "expression is not callable, string has no call signatures" in the el.innerHTML code.

  let consentDataxString: string = dataFromApi?.selectedData.toString() || '';
  let el = document.createElement( 'html' )
  el.innerHTML(consentDataxString)
about 4 years ago · Juan Pablo Isaza
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