Last active
August 29, 2015 14:21
-
-
Save morten-olsen/ab2a0cd669d566abb654 to your computer and use it in GitHub Desktop.
A simple gist for easily extracting elements from a DOM element into a pretty hierarchical structure
This file contains hidden or 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
Node.prototype.find = function (elms) { | |
if (typeof elms === 'string') { | |
return this.querySelector(elms); | |
} | |
var result = {}; | |
for (var key in elms) { | |
result[key] = this.find(elms[key]); | |
} | |
return result; | |
}; |
This file contains hidden or 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 details = document.find({ | |
header { | |
logo: '#header img', | |
title: '#header h1' | |
}, | |
article : 'article' | |
}); | |
details.header.title.innerHTML = 'test'; | |
document.find('#header h1').innerHTML = 'test'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment