Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created September 15, 2012 13:17
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 Raynos/3727806 to your computer and use it in GitHub Desktop.
Save Raynos/3727806 to your computer and use it in GitHub Desktop.

Unpack-element

Unpacks an element into a map of children ids & nodes

Example

/*
    <div>
        <input id="in" />
        <div id="out></div>
    </div>
*/
var elem = above element
    , unpack = require("unpack-element")
    , ever = require("ever")
    , elements = unpack(elem)
    
ever(elements.in).on("keypress", function (ev) {
    elements.out.textContent = elements.in.value
})
var walk = require("dom-walk")
module.exports = unpack
function unpack(elem) {
var struct = {}
walk([elem], function (node) {
if (node.id) {
var id = node.id
node.removeAttribute("id")
struct[id] = node
}
})
return struct
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment