Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!