How to set the checkbox state in local-storage after an event is fired

How to set the checkbox state in local-storage after an event is fired

I have a checkbox input that is checked by default, which toggles the visibility of an element on the page. I want users options to be saved when they refresh the page.

I have a checkbox input that is checked by default, which toggles the visibility of an element on the page. I want users options to be saved when they refresh the page.

var c = document.createElement('input')
c.setAttribute("type", "checkbox")
c.checked = true

c.onclick = function(){ if(c.checked) element.style.display = 'block' if(c.checked == false) element.style.display = 'none' }

/* This code below saves the state of the checkbox, but never fires the event or updates the element */

c.checked = (localStorage.getItem('cchecked')== 'true'); c.onchange = function(){ localStorage.setItem('cchecked', c.checked) }


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Rummy Game Software Development

Rummy Game Software Development- Mobiweb Technologies is India's leading Rummy Game Software provider company having expertise in providing Rummy website and app development solutions.

Card Game Development

Card Game Development Solutions-Mobiweb is an expert Card Game App and Software development company having expertise in design and development of all type of card games.

Rummy Game Development

Rummy Game Software Development- Mobiweb Technologies is India's leading Rummy Game Software provider company having expertise in providing Rummy website and app development solutions.