This works:
var $first = $('body').children('div'), // Finds the first level
output = []; // Stores the results
while ($first.length != 0) { // While we still can go deeper
output = $.merge(output, assemble($first)); // Get the classes on this level
$first = $first.children('div'); // Dive deeper
}
console.log(output); // Output the results
function assemble(l) { // Collects classes at a level
var arr = [];
$.each(l, function() {
arr.push($(this).attr('class'));
});
return arr;
}