Skip to content

Instantly share code, notes, and snippets.

@samarpanda
Created September 10, 2015 05:51
Show Gist options
  • Select an option

  • Save samarpanda/5851474aeabaa4a477e7 to your computer and use it in GitHub Desktop.

Select an option

Save samarpanda/5851474aeabaa4a477e7 to your computer and use it in GitHub Desktop.
Getting all css properties of a dom element in pure javascript
// Got from this url: http://acuriousanimal.com/blog/2012/07/09/look-mom-no-jquery-getting-all-css-properties-of-a-dom-element-in-pure-javascript/
function getComputedStyle( dom ) {
var style;
var returns = {};
// FireFox and Chrome way
if(window.getComputedStyle){
style = window.getComputedStyle(dom, null);
for(var i = 0, l = style.length; i < l; i++){
var prop = style[i];
var val = style.getPropertyValue(prop);
returns[prop] = val;
}
return returns;
}
// IE and Opera way
if(dom.currentStyle){
style = dom.currentStyle;
for(var prop in style){
returns[prop] = style[prop];
}
return returns;
}
// Style from style attribute
if(style = dom.style){
for(var prop in style){
if(typeof style[prop] != 'function'){
returns[prop] = style[prop];
}
}
return returns;
}
return returns;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment