--- title: Creating a simple theme switcher date: 2021 Dec 08 --- This is a simple tutorial on how to make a simple theme switcher.
The first step is to create the themes in your stylesheet, you can have as many as you want. Just make sure to remeber all their names within your CSS.
This is why you need to remeber all their names within the CSS. You need to add them all to an array in your JS. Below is an example of an array containing some themes.
This is the part you've been waiting for! The actual content switcher. It's surprisingly simple.
First, get the index of the current theme using let currentTheme = themes.indexOf(document.documentElement.className). Then, use an if statement to see if it's more than or equal to the length of the array containing your themes.