Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Children method on dom.Element #81

Open
inliquid opened this issue Aug 7, 2021 · 0 comments
Open

Missing Children method on dom.Element #81

inliquid opened this issue Aug 7, 2021 · 0 comments

Comments

@inliquid
Copy link
Contributor

inliquid commented Aug 7, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant