javascript – change surrounding tags for a given text by RegExp
I try to create function that find text in my htmlString (it minify) and then change the tag that wrap the text to h2
var htmlString = `
<h1>title</h1><p>Lorem ipsum dolor quas!</p><p>Lorem ipsum dolor</p><p>hi</p><p>hi 123</p><div>hi</div><span>Lorem ipsum dolor, sit.</span>
`
const changeTagByText = (html) => {
let text = "hi"
// replace the tags
return html
}
console.log(changeTagByText(html))
output excepted:
<h1>title</h1><p>Lorem ipsum dolor quas!</p><p>Lorem ipsum dolor</p><h2>hi</h2><p>hi 123</p><h2>hi</h2><span>Lorem ipsum dolor, sit.</span>
Read more here: Source link