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

125
Vistas
Problem adding link in anchor inside paragraph with dom

I am trying to add an href in an anchor that is inside a paragraph.

var newa= document.createElement('p'); 
  newa.innerHTML = "<span>Or</span> <a>make your renewal payment</a>";

I added it this way because the client needs them to have different styles with a border in the anchor only.

I tried this:

var linkdiv = document.querySelector(".renewnow"); /*parent div*/
const getlink = linkdiv.getElementsByTagName("a");
getlink.href="/newa"

I feel it's not possible to do that, but I tried it anyway

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The way you are trying to handle the element with innerHTML is not wrong, but then you have a string that you have to work with and the only way to modify this string is using Regex. But there is an easier way if you just create all required elements.

const p = document.createElement('p');
const span = document.createElement('span');
span.innerText = 'Or ';
const a = document.createElement('a');
a.innerText = 'make your renewal payment';
a.href = 'https://example.com';

p.append(span);
p.append(a);

document.body.append(p);

about 4 years ago · Santiago Gelvez 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