+ 1
How can I save variable's value in a function that restarts everytime I click on an html element?
For example, change div's background-color to a sequence of colors previusly specified, when the variable that i want to save is the index of the color's array (Sorry for my bad english)
7 Réponses
+ 1
Make 'change' as global variable,
+ 7
Aditya Khandelwal your all answers seems to be directly copy pasting from other sites or external resource. If you want to help then post the links or your own answer
Read the guideline before posting in the forum.
Like your this answer is came from directly from this site.
https://stackoverflow.com/questions/16206322/how-to-get-js-variable-to-retain-value-after-page-refresh
https://www.sololearn.com/Content-Creation-Guidelines/
+ 2
Luis Méndez I have some questions to help me better understand your question, so that I can provide a proper response.
My understanding is you have a function that gets called during a click event. This function also declares some local variables with values you'd like to carry over between subsequent clicks. However, the variables are reset every time the function is called. Is this correct?
It sounds like this would be a good use case for closures. However, I want to confirm this is what you are asking.
+ 1
David Carroll yes, i want to save that variables
0
Luis Méndez Add some code to Code Playground and show me what you have so far. It will be easier to work through the solution with an actual example of your issue.
Post a link here for us to review.
0
It works! Thanks!! Daniel Sabrel