Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda