Skip to content

Instantly share code, notes, and snippets.

@gjjones
Created April 10, 2014 18:38
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 gjjones/10410377 to your computer and use it in GitHub Desktop.
Save gjjones/10410377 to your computer and use it in GitHub Desktop.
generate computed styles for node down through children
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