Created
September 10, 2015 05:51
-
-
Save samarpanda/5851474aeabaa4a477e7 to your computer and use it in GitHub Desktop.
Getting all css properties of a dom element in pure javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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