@SempervivumFeb 22.2020 — #Your first fiddle works fine when you read the theme from the local storage and apply it to document.body: document.querySelectorAll('.btn-theme').forEach((item) => { item.addEventListener('click', (event) => { window.localStorage.setItem('theme', item.dataset.theme); alert(localStorage.theme + " is stored") }); }); document.body.dataset.theme = localStorage.getItem('theme');
In your second fiddle you are using the onload event. Unfortunately jsfiddle (by default) does the same, it calls the javascript onload. Therefore that event has already fired when your javascript is executed and won't fire again. You can view and adjust the load type, i. e. the event when the javascript is executed, by the JS setting: The small down triangle on top of the javascript window.
@sibertauthorFeb 23.2020 — #> @Sempervivum#1615109 In your second fiddle you are using the onload event. Unfortunately jsfiddle (by default) does the same, it calls the javascript onload.