Last active
November 22, 2019 03:15
-
-
Save jasondmoss/b46198f27fb288a481f995a3cdb12abc to your computer and use it in GitHub Desktop.
Create a new element with provided attributes.
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
/** | |
* Create a new element with provided attributes. | |
* | |
* @param {String} name Element name. | |
* @param {Object|Array} attrs Element attributes. | |
* | |
* @return {Object} Element | |
*/ | |
// jshint esversion: 6 | |
const createElementWithAttr = (name, attrs) => { | |
"use strict"; | |
let elem = document.createElement(name.toString()); | |
Object.keys(attrs).forEach( | |
key => elem.setAttribute(key, attrs[key]) | |
); | |
return elem; | |
}; | |
/* <> */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment