- From: Noam Rosenthal <notifications@github.com>
- Date: Wed, 15 Oct 2025 13:02:21 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Wednesday, 15 October 2025 20:02:25 UTC
noamr left a comment (whatwg/dom#1406)
This version is probably sufficient for any practical use (unless you really need the runtime is-element nodeType checks):
```js
function insertOrMoveBefore(parent: Element, child: Element, ref: Node?) {
if (child.isConnected && parent.isConnected &&
(child.ownerDocument === parent.ownerDocument)) {
parent.moveBefore(child, ref);
else
parent.insertBefore(child, ref);
}
```
or:
```js
function insertOrMoveBefore(parent, child, ref) {
try {
parent.moveBefore(child, ref);
} catch (e) {
parent.insertBefore(child, ref);
}
}
```
Some of the other premutations like moving `CharacterData` are not that interesting if you're anyway falling back to `insertBefore`.
I don't mind having this as part of the platform (and it was discussed before) but the polyfill is perhaps not that bad?
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1406#issuecomment-3408052696
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/dom/issues/1406/3408052696@github.com>
Received on Wednesday, 15 October 2025 20:02:25 UTC