8000 Missing `Children` method on `dom.Element` · Issue #81 · dominikh/go-js-dom · GitHub
[go: up one dir, main page]

Skip to content

Missing Children method on dom.Element #81

Open

Description

@inliquid

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0