diff --git a/packages/sage-system/lib/tooltip.js b/packages/sage-system/lib/tooltip.js index 71d3494c82..6a32466878 100644 --- a/packages/sage-system/lib/tooltip.js +++ b/packages/sage-system/lib/tooltip.js @@ -53,17 +53,18 @@ Sage.tooltip = (function() { positionTooltip(evt.target, tooltip, pos); } - // Removes tooltip from DOM function removeTooltip(evt) { - if (!evt.target.hasAttribute(DATA_ATTR) || !document.querySelector(SELECTOR) || !document.querySelector(`.${TOOLTIP_CLASS}`) || !evt.target.dataset.jsTooltip) return; + if (!evt.target.hasAttribute(DATA_ATTR) || !document.querySelector(SELECTOR) || !document.querySelector(`.${TOOLTIP_CLASS}`) || !evt.target.dataset.jsTooltip) return; window.requestAnimationFrame(function() { - document.body.removeChild(document.querySelector(`.${TOOLTIP_CLASS}`)); + var tooltip = document.querySelector(`.${TOOLTIP_CLASS}`); + if (tooltip && tooltip.parentNode === document.body) { // Ensure tooltip exists and its parent is document.body before removing + document.body.removeChild(tooltip); + } }); } - // Builds list of modifier classes from array of data-attributes function generateClasses(ele, evt) { ele.dataItems.forEach(function(item) {