Skip to content

Commit

Permalink
Destroy all dynamically inserted styles
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayPoshak committed Nov 30, 2019
1 parent b716692 commit 326d39b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function Coachmark() {
let currentStep = 0;
let highlighter = null;
let tooltipTextElement = null;
let styleClass = 'coachmark-styles'

const overlayStyles = `
top: 0;
Expand Down Expand Up @@ -180,6 +181,11 @@ function Coachmark() {
if (mountPoint) mountPoint.remove();
if (nextBtn) nextBtn.removeEventListener("click", handleNextBtnClick);
if (skipBtn) skipBtn.removeEventListener("click", handleSkipClick);
// Destroy all dynamically inserted styles
const allDynamicStyles = document.getElementsByClassName(styleClass)
if(allDynamicStyles.length) {
Array.from(allDynamicStyles).forEach(dynamicStyle => dynamicStyle.remove())
}
}

function getCoachmarkElements() {
Expand All @@ -201,6 +207,7 @@ function Coachmark() {
function addStyles(selector, styles) {
if (styles.length) {
const style = document.createElement("style");
style.classList.add(styleClass)
document.head.appendChild(style);
const styleSheet = style.sheet;
styleSheet.insertRule(
Expand Down

0 comments on commit 326d39b

Please sign in to comment.