Cannot set property ‘className’ of null at setThemeFromCookie
Using JQuery Simplifies the whole thing, using JS Cookie $(document).ready(function(){ // Check cookie and set theme if(Cookies.get(‘theme’)) { $(‘body’).removeClass(‘light-mode dark-mode’).addClass( Cookies.get(‘theme’) ); }; //Switch theme and create the cookie… $(“#theme-toggler”).click(function(){ if ($(‘body’).hasClass( ‘light-mode’)){ $(‘body’).removeClass(‘light-mode’).addClass(‘dark-mode’); Cookies.set(‘theme’, ‘dark-mode’); }else { $(‘body’).removeClass(‘dark-mode’).addClass(‘light-mode’); Cookies.set(‘theme’, ‘light-mode’); } }); }); Add id to button. <button id=”theme-toggler” type=”button” name=”dark_light” title=”Toggle dark/light mode”>🌛</button> … Read more