✌️
I am trying to replace an html parent element with its child elements using "github.com/PuerkitoBio/goquery". However, ReplaceWithSelection does not replace anything and the selection remains unchanged.
package main
import (
"os"
"strings"
"github.com/PuerkitoBio/goquery"
)
var html = `
<section>
<article>
<h2>Article 1</h2>
<p>Text for article #1</p>
</article>
<article>
<h2>Article 2</h2>
<p>Text for article #2</p>
</article>
</section>
`
func main() {
qHtml, err := goquery.NewDocumentFromReader(strings.NewReader(html))
if err != nil {
panic(err)
}
section := qHtml.Find(`section`)
sectionChildren := section.Children().Clone()
section.ReplaceWithSelection(sectionChildren)
goquery.Render(os.Stdout, section)
}