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

203
Visualizações
How can I remove an <h2> dynamically?

Maybe this is a basic question, but I should stress I know very little about these things. Essentially, in my page I have something like:

<h2>Some text there</h2>
<h2>Other text there</h2>

And I would like to make it simply into:

Some text there
Other text here

I mean, essentially, I want to remove the H2 surrounding the text. It'd be super easy to just delete it, but unfortunately I only have indirect access to the code. Is there any way to remove this dynamically using Javascript?

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

0

You can loop through all h2 elements and replace each element with a text node of the element's textContent (with document.createTextNode):

document.querySelectorAll('h2').forEach(e => e.parentNode.replaceChild(document.createTextNode(e.textContent), e))
<h2>Some text there</h2>
<br/>
<h2>Other text there</h2>

about 4 years ago · Juan Pablo Isaza Relatório

0

Eventually, I found this solution, which was perfect for my case, but I'd also want to thank everyone who posted here!

document.addEventListener('DOMContentLoaded', e => {
    const h2s = document.querySelectorAll("h2")

    h2s[0].outerHTML = h2s[0].innerHTML
    h2s[1].outerHTML = h2s[1].innerHTML
})
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