Check out this toggle demo from Educative
window.localStorage
cookies vs sessionStorage( ) vs localStorage( )
uses for local storage
- store user preferences (i.e. dark / light mode)
- store user interaction (i.e. dismissed a message / modal)
- store non-sensitive info (i.e. user first name)
- store user form data for longer or multi-part forms (i.e. ski school)
- store json data using JSON.stringify( ) & JSON.parse( );
Local Storage Methods
- setItem( ); — adds / sets a key/value pair
- getItem( ); — retrieves key/value pairs
- removeItem( ); — deletes key/value pair
- key( ); — gets keys by index
- clear( ); — clears localStorage
Check out this article on cookies vs sessionStorage vs localStorage
demos
form info
modal
booking
clear localStorage( );
clear localStorage( );Modal Example
This modal example is taken from CSS Tricks: Considerations for Styling a Modal