Reputation: 1542
Is there anyway to just store the current style state of an element, so i can botch up the styling then jsut reset it?
Something similar to (although this doesnt work): http://jsfiddle.net/843Pj/
var el=document.getElementById('test');
var st=(function(s){
var r=function(){return s;};
return r;
}(el.style));
el.style.backgroundColor='blue';
el.style=st();
alert(el.style);
Upvotes: 2
Views: 92
Reputation: 10972
If you're talking just about the original inline styles, the use the .cssText
property of the style
object.
var st = el.style.cssText; // store it
el.style.backgroundColor = 'blue'; // change it
el.style.cssText = st; // reset it
You could even store it on a data-
attribute of the element for easy access later.
Upvotes: 2