Re: [whatwg/dom] Proposal: ParentNode.empty() (#478)

fwiw setting textContent and setting innerHTML are not the same. `documentElement.innerHTML = ""` will insert a `<head>` and `<body>` so you're not left with no children. innerHTML invokes the parser and may actually insert children even when an empty string is passed, there's a number of elements with different parsing behavior. Doing `.textContent = null` (or empty string) will always remove all the children (ignoring mutation events) though.

It looks like Gecko has an optimization for innerHTML:
https://dxr.mozilla.org/mozilla-central/source/dom/base/FragmentOrElement.cpp#2493

and enumerates all the special cases for parsing:
https://dxr.mozilla.org/mozilla-central/search?q=%2Bcallers%3AnsINode%3A%3ASetHasWeirdParserInsertionMode%28%29

WebKit and Blink don't do that, but probably should.

I do think a `removeChildren()` API would make more sense though since it removes the attractive footgun of innerHTML with its special cases. The DOM is hard enough to use already, having to remember the right way to remove all the children shouldn't be something authors need to worry about.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/478#issuecomment-344510087

Received on Wednesday, 15 November 2017 07:38:27 UTC