Skip to content

Instantly share code, notes, and snippets.

@niittymaa
Forked from carymrobbins/get_css.js
Created September 7, 2016 09:17
Show Gist options
  • Save niittymaa/d3a5cc1b82d4aeae5b22974d7316dd14 to your computer and use it in GitHub Desktop.
Save niittymaa/d3a5cc1b82d4aeae5b22974d7316dd14 to your computer and use it in GitHub Desktop.
Get all CSS attributes for an element.
var getCss = function(el) {
var style = window.getComputedStyle(el);
return Object.keys(style).reduce(function(acc, k) {
var name = style[k],
value = style.getPropertyValue(name);
if (value !== null) {
acc[name] = value;
}
return acc;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment