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

Implement children property on Node? #410

Open
retorquere opened this issue May 9, 2022 · 1 comment
Open

Implement children property on Node? #410

retorquere opened this issue May 9, 2022 · 1 comment
Labels
help-wanted External contributions welcome spec:DOM Living Standard https://dom.spec.whatwg.org/
Milestone

Comments

@retorquere
Copy link

retorquere commented May 9, 2022

With this script:

const { DOMParser } = require('@xmldom/xmldom')
let source = '<div id="note-body">note</div>';
const parser = new DOMParser()
doc = parser.parseFromString(source, 'text/html');
let root = doc.getElementById('note-body');
console.log(root.children)

I get undefined. Should nodes/the root element not have children properties as per https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString ?

@karfau
Copy link
Member

karfau commented Jun 11, 2022

I'm sorry for the late reply.

There is no children property in the DOM API, also the page you linked doesn't mention children anywhere. Even though the DOM specification mentions the word a lot, it's rather a concept, not a property or getter: https://dom.spec.whatwg.org/#concept-tree-child

What you might be looking for is childNodes.

I was wrong, according to https://dom.spec.whatwg.org/#dom-parentnode-children

The children getter steps are to return an HTMLCollection collection rooted at this matching only element children.

But xmldom is currently not implementing this (we don't even have an HTMLCollection yet).

The closest workaround is to filter childNodes by nodeType

@karfau karfau closed this as completed Jun 11, 2022
@karfau karfau reopened this Jun 11, 2022
@karfau karfau added help-wanted External contributions welcome spec:DOM Living Standard https://dom.spec.whatwg.org/ labels Jun 11, 2022
@karfau karfau added this to the before 1.0.0 milestone Jun 11, 2022
@karfau karfau changed the title no 'children' property on nodes? Implement children property on Node? Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help-wanted External contributions welcome spec:DOM Living Standard https://dom.spec.whatwg.org/
Projects
None yet
Development

No branches or pull requests

2 participants