Question:
JavaScript - temporary value storage?
Es
2010-07-01 13:52:30 UTC
I have a collection of DIV elements and I set their background color to a particular value inside JavaScript, then I call setTimeout to reset the background color. In short, I highlight these DIVs for a second. The problem is that prior to highlighting DIVs may have different colors and I need to remember this value and then restore it. Is there a simple way to store this value inside DIV itself? Maybe it has some string attribute which I could use for that (one that wont influence DIV appearance). I just want to avoid unnecessary Arrays.

Thanks.
Three answers:
Thai
2010-07-01 16:59:56 UTC
If fact, you can store any values inside any unused property of any element like this:



myDiv.oldBackgroundColor = myDiv.style.backgroundColor;
53MalePrison
2010-07-01 13:59:49 UTC
This may or may not suit the needs ... but how about using one of the event attributes to pass the color?



For example, add onmouseover("Red") -- assuming red was the original color.

Then when you need to retrieve back the original color, call the event.
anonymous
2016-03-03 09:38:22 UTC
In many places. For example, between functional units in a pipeline system. Also, in serial communications


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...