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) }


javascript game-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

ludo game development.ludo game development company.ludo king game app development

We are here to bridge your dreams to reality by offering you the best ludo game development. Our Ludo game software development is the best option to choose if you want to launch a game like ludo king in a short time.

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.

Card Game App 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.