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

109
Vistas
Preview URL for dynamically created link

I have a anchor tag. On click of it, I create an anchor tag and set the href attribute.

Something like this:

<a onClick={() => linkClick(url)}> Text </a>


 const linkClick = (url) => {
        const tag= document.createElement('a');
        tag.rel = 'noopener noreferrer';
        tag.target = _blank';
        tag.href = url;
        tag.click();
}

The issue I am facing here is, when I hover over the a tag, the URL preview is not available (Which usually appears at the bottom left) since href attribute is not present. Can you please help me here. (I dont want to add href attribute).

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

As far as I can tell, you have the dynamic URL when you render the link. Why not just render the component fully with React? If you are going to use React to render your component, I suggest you steer clear of changing the DOM element like that afterwards.

<a 
  href={url}
  rel="noopener noreferrer"
  target="_blank"
>
  Text
</a>
about 4 years ago · Juan Pablo Isaza Denunciar

0

Add the href prop to the anchor tag, and then call preventDefault() in the linkClick` function like so:

<a href={url} onClick={linkClick}> Text </a>

 const linkClick = (e) => {
        e.preventDefault()
        const tag= document.createElement('a');
        tag.rel = 'noopener noreferrer';
        tag.target = '_blank';
        tag.href = e.target.href;
        tag.click();
}
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