Without jQuery, it elegantly creates an element with attributes.
This file contains 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
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