diff --git a/src/htmx.js b/src/htmx.js index 7a6e2358..dbdd2e10 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -1741,7 +1741,10 @@ return (function () { } catch (e) { logError(e); } finally { - parent.removeChild(script); + // remove old script element, but only if it is still in DOM + if (script.parentElement) { + script.parentElement.removeChild(script); + } } } }