Join Nostr
2026-05-21 13:54:21 UTC

Harald on Nostr: Weird #JavaScript behavior with Element.remove(): const children = ... // sorted ...

Weird #JavaScript behavior with Element.remove():

const children = ... // sorted children of container
children.forEach((ch) => ch.remove());
if (1 > 2) {
setTimeout(() => {
for (const child of children) {
container.append(child);
}
}, 0);
} else {
for (const child of children) {
container.append(child);
}
}

The setTimeout branch works, the other not. Anyone? would you have an idea?

A shallow explanation: removal needs one round of the event loop. But why?