Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
show elements computed style
window.getComputedStyle = window.getComputedStyle || function( element ) {
return element.currentStyle;
}
//https://stackoverflow.com/questions/22907735/get-the-computed-style-and-omit-defaults
function getStylesWithoutDefaults( element ) {
var dummy = document.createElement(element.tagName);
document.body.appendChild( dummy );
var defaultStyles = getComputedStyle( dummy );
var elementStyles = getComputedStyle( element );
var diff = {};
for( var key in elementStyles ) {
if(elementStyles.hasOwnProperty(key)
&& defaultStyles[ key ] !== elementStyles[ key ] )
{
diff[ key ] = elementStyles[ key ];
}
}
dummy.remove();
return diff;
}
window.addEventListener("click",function(e){
let x = e.clientX, y = e.clientY,
elementMouseIsOver = document.elementFromPoint(x, y)
var data = getStylesWithoutDefaults(elementMouseIsOver)
console.log(data)
},false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.