Skip to content

Instantly share code, notes, and snippets.

@jasonreiche
Created December 3, 2021 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonreiche/a299620afdb1758b669d8fbda6d64a95 to your computer and use it in GitHub Desktop.
Save jasonreiche/a299620afdb1758b669d8fbda6d64a95 to your computer and use it in GitHub Desktop.
Get unique styles assigned to any element matching a query selector
[...document.querySelectorAll("#targets")].forEach(targetEl => {
var targetStyles = window.getComputedStyle(targetEl);
var comparisonEl = document.createElement(targetEl.tagName);
var comparisonStyles = window.getComputedStyle(comparisonEl);
var cleanStyles = {};
Object.entries(targetStyles).forEach(style=>{
if(comparisonStyles[style[0]] !== style[1]){
cleanStyles[style[0]] = style[1];
}
});
console.log('CLEAN SET (' + Object.keys(cleanStyles).length + ' rules):',cleanStyles);
comparisonEl.remove()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment