Jump to content


Popular Content

Showing content with the highest reputation on 11/08/2019 in all areas

  1. 1 point
    The first line always reset it on every reload, you only need that to happen when it has not already been set and is empty. Also the JavaScript code needs to below any element it references as the page is rendered from top to bottom, the jS code is executed before the elements it is referencing even exist producing undefined error. You are overthinking this, all you need do is set localStorage.fontsize=1; or localstorage.fontsize=2; and so on... On click event it should increment a variable on each click then reset if greater than 3 the use if conditions n++; if(n > 3){ n=1; } localStorage.fontsize=n; if (localStorage.fontsize==1){ document.getElementById("a").style.fontSize = "20px"; } // and so on... On load you should see if fontsize exists else set to defalut if (localStorage.fontsize) { if (localStorage.fontsize==1){ document.getElementById("a").style.fontSize = "20px"; } // and so on... else { localstorage.fontsize=1; }
  2. 1 point
    Localstorage will do that. First you set a default value if localstorage does not currently store any value related to chosen font size, else load localstorage value and make the chosen font-size active on page load or refresh. Then set onclick event to make selected fontsize active then at same set localstorage to store currently selected font-size also.
  • Create New...