diff --git a/lib/on-resize.js b/lib/on-resize.js index 2a95225..4642cff 100644 --- a/lib/on-resize.js +++ b/lib/on-resize.js @@ -75,9 +75,11 @@ const initialize = (el) => { } detector.destroy = () => { if (detector.elWasStaticPosition) el.style.position = "" - // Event handlers will be automatically removed. - // http://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory - el.removeChild(objEl) + if (el.contains(objEl)) { + // Event handlers will be automatically removed. + // http://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory + el.removeChild(objEl); + } } el.appendChild(objEl)