Skip to content

@fracmak /elementToObject forked from alain75007/elementToObject
Last active

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
* Given an html element or jquery object, will return a serializable object representation of that node
* @param {HTMLElement|jQuery} element
* @param {Boolean} [recurse] - specifying whether we want to build objects for the children
* @returns {Object}
function elementToObject(element, recurse) {
var el = $(element),
o = {
tagName: el[0].tagName
_.each(el[0].attributes, function(attribute){
o[] = attribute.value;
if (recurse) {
o.children =, function(child){
return this.elementToObject(child, true);
}, this);
return o;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.