Skip to content Skip to sidebar Skip to footer

How To Load/unload Css Dynamically

I know how to load CSS. injectCss(styles) { let styleSheet = document.createElement('style'); styleSheet.type = 'text/css'; styleSheet.innerText = styles; document.head.ap

Solution 1:

Hope this help you.

function injectCss(styles) {
  let styleSheet = document.createElement("style");
  styleSheet.type = 'text/css';
styleSheet.setAttribute("id", "dunamicstylesheet");
  styleSheet.innerText = styles;
  document.head.appendChild(styleSheet);
}

//Create-styleSheet
injectCss('dynamic.css');

//remove-styleSheet
var stylesheet = document.getElementById('dunamicstylesheet');
stylesheet.parentNode.removeChild(stylesheet);

Post a Comment for "How To Load/unload Css Dynamically"