function createElement(type, attributes) {
var element = document.createElement(type);
for (var key in attributes) {
if (key == "class") {
element.classList.add.apply(element.classList, attributes[key]); // add all classes at once
} else {
element[key] = attributes[key];
}
}
someElement.appendChild(element);
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter