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?
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>
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
})