If I do:
var el =
{
o : document.createElement(\"iframe\")
}
var fs = JSON.stringify(el);
and then I try to access with
var ofs = JSON.parse(fs);
Building on Alain's prototypejs code, I've updated it using underscore and jQuery, also put into a gist here
function elementToObject(element, recurse) {
var el = $(element),
o = {
tagName: el[0].tagName
};
_.each(el[0].attributes, function(attribute){
o[attribute.name] = attribute.value;
});
if (recurse) {
o.children = _.map(el.children(), function(child){
return this.elementToObject(child, true);
}, this);
}
return o;
}