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

124
Visualizações
How to open multiple links from a single hyperlink from anchor tag string in React?

I have a string that has multiple anchor tags passed to the frontend in ReactJs. This string is given by the service call.

eg: "<a href=\"https://www.google.com\" target=\"_blank\"> National ID </a><a href=\"https://www.yahoo.com\" target=\"_blank\"> National ID </a>"

I want to display National ID once and open both the links on a blank page. I figured it out that by getting the href links, I can create an onclick function that opens both the links.

I wanted to know, how to extract href from the string. Or is there a better way to solve the issue that I have? Thanks in advance for any suggestions and solutions.

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

0

Updated

So if you have high volume of anchor tags, then you can extract all the href values and add the href values in the array.

Code given below

 

let hrefValues=document.getElementsByTagName('a')

let hrefArray = [];

for (var i = 0; i<hrefValues.length; i++)

{  

    hrefArray.push(hrefValues[i].href);

}

 

console.log(hrefArray);

 
 


 

<a href="https://www.google.com/1" target="_blank">

<a href="https://www.google.com/2" target="_blank">

<a href="https://www.google.com/3" target="_blank">

<a href="https://www.google.com/4" target="_blank">

<a href="https://www.google.com/5" target="_blank">

 

about 4 years ago · Juan Pablo Isaza Relatório

0

Use regex to parse string and extract links, like this one:

const input = '<a href="https://www.google.com" target="_blank"> National ID </a><a href="https://www.yahoo.com" target="_blank"> National ID </a>';
const regex = /href="(\S*)"/g;
const links = Array.from(input.matchAll(regex), m => m[1]);
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