DEV Community

Discussion on: how to store button state from onclick event

Collapse
 
benjioe profile image
Benjioe • Edited

You can store it :

  • in a global variable, a data-attributes or an input (type="hidden") but reloading the page will reset score.
  • in local storage or in a cookie but it's harder and cleaning browser's history will reset score.
  • in the URL with history.pushState but it's harder and the player have to remember the URL to keep score.
  • on a server who's the only way to prevent cheating, but you need a server and it's harder.

Or

  • do not store state, just rebind, but it's harder and reloading the page will reset score.