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
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 Respostas
Responde à pergunta

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 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