If you're on Chrome/Safari, initial
works just fine for what you want to do. After setting it, you'll see the active style as initial
and the the computed style as the browser default.
But to set the active styles to the default, create a temporary element and set your element properties to the the temporary values.
Demo: http://jsfiddle.net/ThinkingStiff/Yb9J9/
Script:
Element.prototype.setDefaultStyles = function () {
var element = document.createElement( this.tagName ),
styles = window.getComputedStyle( element ),
display = styles.getPropertyValue( 'display' );
element.style.display = 'none';
document.body.appendChild( element );
for( style in styles ) {
this.style[styles[style]] = styles.getPropertyValue(styles[style]);
};
this.style.display = display;
document.body.removeChild( element );
};
document.getElementById( 'unstyled' ).setDefaultStyles();
HTML:
<div id="styled">styled</div>
<div id="unstyled">unstyled</div>
CSS:
#styled, #unstyled {
border: 1px solid red;
color: green;
width: 100px;
height: 50px;
}
Output:
