The replaceWith() function as documented here does not work in IE:
https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/r...
You may be able to find hacky alternatives, but if you use jQuery you don't have to.
Here it is in the form of a basic polyfill that only supports Elements:
Element.prototype.replaceWith = function(replacement) {
if (typeof replacement === "string") {
replacement = this.ownerDocument.createTextNode(replacement);
}
this.parentNode.replaceChild(this, replacement);
}EDIT: Regarding the polyfill, now you are beginning to write your own little jQuery clone.
Why is that a worthwhile goal?
A polyfill is something that's not needed at all in modern browsers and thus can be considered pretty much final. jQuery is actually surprisingly stable compared to Angular/React/npm/rest-of-the-hipster-crap, but it has had its fair share of incompatibilities too.