I’m going to use Mousetrap so when a user presses Alt+L it uses jQuery and adds the class light to body tag, I’d also like it to remove the class once Alt+L is pressed.
How can I add localstorage to remember if there is class light?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I won’t provide the code because it’s so simple that I don’t need to. Instead, I will provide you guidance to use documentation which will give you answers to the api’s you request information about.
localStorageis incredibly straight forward. It’s a simple key/value store.https://developer.mozilla.org/en-US/docs/DOM/Storage
The Mozilla Developer Network will provide you information on what api’s do and how they work (with working examples).
I’d also like to mention, that there is likely questions about
localStorageon StackOverflow already. Here is a post on StackOverflow – Modify localstorage?Welcome.
To match the OP’s REAL question, “How can I use localStorage to remember which classes were set on an element”.