Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Without jQuery, it elegantly creates an element with attributes.
function createElement(type, attrs) {
return Object.keys(attrs).reduce(
function(el, n) { el[n]=attrs[n]; return el; },
document.createElement(type)
);
}
What does it do? Without jQuery, it elegantly creates an element with attributes.
createElement('a', {
href: 'http://google.com',
style: 'display: block;',
innerText: 'Google!'
});
// HTMLElement
// <a href="http://google.com" style="display: block;">Google!</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.