When using the localStorage
property like
localStorage.setItem('theme', element);
, keep in mind that it does not store the href
property of an element such as element.href = '../assets/css/syntax-highlighting/synthwave-84.css';
:
const lightButton = document.getElementById('theme-light');
const synthwaveButton = document.getElementById('theme-synthwave-84');
const body = document.body;
var check = document.getElementById('theme_css').classList[0] === 'theme-light';
const theme = localStorage.getItem('theme');
var element = document.getElementById('theme_css');
if (theme)
{
body.classList.add(theme);
}
synthwaveButton.onclick = () =>
{
element.href = '../assets/css/syntax-highlighting/synthwave-84.css';
localStorage.setItem('theme', element);
body.classList.replace('theme-dark', 'theme-synthwave-84');
body.classList.replace('theme-light', 'theme-synthwave-84');
body.classList.replace('theme-cyberpunk', 'theme-synthwave-84');
body.classList.replace('theme-tron', 'theme-synthwave-84');
localStorage.setItem('theme', 'theme-synthwave-84');
};
Here is an example of the HTML:
<link rel="stylesheet" href="../assets/css/syntax-highlighting/suru-plus.css" id="theme_css" />