Answers for "how to add theme attribute to :root"

0

how to add theme attribute to :root

const toggleBtn = document.querySelector("#toggle-theme");
toggleBtn.addEventListener('click', e => {
  console.log("Switching theme");
  if(document.documentElement.hasAttribute('theme')){
    document.documentElement.removeAttribute('theme');
  }
  else{
    document.documentElement.setAttribute('theme', 'dark');
  }
});
Posted by: Guest on October-13-2020

Code answers related to "how to add theme attribute to :root"

Code answers related to "Javascript"

Browse Popular Code Answers by Language