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

194
Views
¿Cómo puedo eliminar un <h2> dinámicamente?

Tal vez esta es una pregunta básica, pero debo enfatizar que sé muy poco sobre estas cosas. Esencialmente, en mi página tengo algo como:

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

Y me gustaría convertirlo simplemente en:

 Some text there Other text here

Quiero decir, esencialmente, quiero eliminar el H2 que rodea el texto. Sería muy fácil eliminarlo, pero desafortunadamente solo tengo acceso indirecto al código. ¿Hay alguna forma de eliminar esto dinámicamente usando Javascript?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede recorrer todos los elementos h2 y reemplazar cada elemento con un nodo de texto del contenido de texto del textContent (con 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

Eventualmente, encontré esta solución, que era perfecta para mi caso, ¡pero también quiero agradecer a todos los que publicaron aquí!

 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!