-
-
Notifications
You must be signed in to change notification settings - Fork 42
Open
Description
For reference, I'm using dom/v2 with go1.16.6 to build WASM client for a web project.
I have a case when I parse some arbitrary HTML from the server and add individual elements to DOM based on this. I call SetInnerHTML on some temporary element and then add children one by one. However HTML has whitespaces in it, so returned node may be a text one.
...
newCommentsList := dom.GetWindow().Document().CreateElement("div")
newCommentsList.SetInnerHTML(resp.HTML)
...
for _, commentNode := range newCommentsList.ChildNodes() {
if _, ok := commentNode.(*dom.Text); ok {
//if commentNode.NodeType() == 3 { // or like this
continue
}
...
commentsTop.ParentElement().InsertBefore(commentNode, commentsTop.NextElementSibling())
}
...I could have avoided checking against node type if I had Children method:
https://developer.mozilla.org/en-US/docs/Web/API/Element/children. Other *Element methods, such as ParentElement or NextElementSibling works fine for this purpose.
Metadata
Metadata
Assignees
Labels
No labels