[whatwg/dom] Element.replaceChild should allow for `old, new` argument ordering if `new` is a new element and `old` is a child of Element (#847)

Concretely, given DOM constructed from this HTML:

```html
<div><span id="a">Old</span></div>
```

Running:

```js
document.querySelector("div").replaceChild(document.querySelector("#a"), document.createTextNode("new"));
```

currently throws a DOM Node not found error (cf. step 3 in https://dom.spec.whatwg.org/#concept-node-replace ).

Really, `old, new` argument ordering would IMO make more sense, but completely changing the argument order is probably not realistic.

However, in the case where (a) the second argument has no parent and (b) the first argument **is** a child of the _parent_, instead of throwing an error, we could just Do What the Developer Means -- instead of throwing, which we do now, which is very developer-unfriendly. I'm not even sure if we need the (a) restriction, but certainly that seems like it'd be safer than also doing it if (a) has a different parent.

Of course, perhaps in web-compat practice there are people who depend on the error throwing behaviour? I don't know...

-- 
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/847

Received on Thursday, 12 March 2020 17:42:25 UTC