Created
April 10, 2014 18:38
-
-
Save gjjones/10410377 to your computer and use it in GitHub Desktop.
generate computed styles for node down through children
This file contains 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
var element = document.getElementById('foo'); | |
var nodes = [element]; | |
var value = ''; | |
var counter = 1; | |
while (nodes.length > 0) { | |
element = nodes.shift(); | |
Array.prototype.map.call(element.children, function(node){nodes.push(node);}); | |
value += ['\n/*',counter++,'*/\n'].join(''); | |
var newObj = {}, obj = window.getComputedStyle(element); | |
for (var key in obj) { | |
if (isNaN(parseInt(key)) && key !== 'cssText') | |
newObj[key] = obj[key]; | |
} | |
value += JSON.stringify(newObj, null, " ") | |
} | |
console.log(value); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment