Skip to content

Instantly share code, notes, and snippets.

@joshblack
Last active September 26, 2015 23:46
Show Gist options
  • Select an option

  • Save joshblack/dbbbcb21216c4a111b06 to your computer and use it in GitHub Desktop.

Select an option

Save joshblack/dbbbcb21216c4a111b06 to your computer and use it in GitHub Desktop.
// Usage
const container = div({
id: 'foo',
style: {
background: 'black',
width: '100px',
height: '100px'
}
});
function setDOMProps(node, props) {
Object.keys(props).forEach((prop) => {
if (typeof props[prop] === 'object') {
Object.keys(props[prop])
.forEach((k) => node[prop][k] = props[prop][k]);
} else {
node[prop] = props[prop];
}
});
return node;
}
const div = (props) => setDOMProps(document.createElement('div'), props);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment