diff --git a/js/src/alert.js b/js/src/alert.js index 87cc7e7311..679a90cdb4 100644 --- a/js/src/alert.js +++ b/js/src/alert.js @@ -78,9 +78,7 @@ class Alert extends BaseComponent { } _destroyElement(element) { - if (element.parentNode) { - element.parentNode.removeChild(element) - } + element.remove() EventHandler.trigger(element, EVENT_CLOSED) } diff --git a/js/src/popover.js b/js/src/popover.js index e8614156cd..929391392a 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -98,11 +98,11 @@ class Popover extends Tooltip { this.tip = super.getTipElement() if (!this.getTitle()) { - this.tip.removeChild(SelectorEngine.findOne(SELECTOR_TITLE, this.tip)) + SelectorEngine.findOne(SELECTOR_TITLE, this.tip).remove() } if (!this._getContent()) { - this.tip.removeChild(SelectorEngine.findOne(SELECTOR_CONTENT, this.tip)) + SelectorEngine.findOne(SELECTOR_CONTENT, this.tip).remove() } return this.tip diff --git a/js/src/tooltip.js b/js/src/tooltip.js index 84379c88f2..2eb91965b2 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -208,8 +208,8 @@ class Tooltip extends BaseComponent { EventHandler.off(this._element.closest(`.${CLASS_NAME_MODAL}`), 'hide.bs.modal', this._hideModalHandler) - if (this.tip && this.tip.parentNode) { - this.tip.parentNode.removeChild(this.tip) + if (this.tip) { + this.tip.remove() } if (this._popper) { @@ -314,8 +314,8 @@ class Tooltip extends BaseComponent { return } - if (this._hoverState !== HOVER_STATE_SHOW && tip.parentNode) { - tip.parentNode.removeChild(tip) + if (this._hoverState !== HOVER_STATE_SHOW) { + tip.remove() } this._cleanTipClass() diff --git a/js/src/util/backdrop.js b/js/src/util/backdrop.js index c05c221ddf..f7990f7019 100644 --- a/js/src/util/backdrop.js +++ b/js/src/util/backdrop.js @@ -116,11 +116,7 @@ class Backdrop { EventHandler.off(this._element, EVENT_MOUSEDOWN) - const { parentNode } = this._getElement() - if (parentNode) { - parentNode.removeChild(this._element) - } - + this._element.remove() this._isAppended = false } diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index 5fc94275c8..d1e55a2b1e 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -108,7 +108,7 @@ export function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) { const elName = el.nodeName.toLowerCase() if (!allowlistKeys.includes(elName)) { - el.parentNode.removeChild(el) + el.remove() continue }