Skip to content

Instantly share code, notes, and snippets.

@jasondmoss
Last active November 22, 2019 03:15
Show Gist options
  • Save jasondmoss/b46198f27fb288a481f995a3cdb12abc to your computer and use it in GitHub Desktop.
Save jasondmoss/b46198f27fb288a481f995a3cdb12abc to your computer and use it in GitHub Desktop.
Create a new element with provided attributes.
/**
* 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