Skip to content

Instantly share code, notes, and snippets.

@nickytonline
nickytonline / createElement.js
Last active December 11, 2024 01:13
A Handy DOM element creation function.
// Inspired from Sam Thorogood's article, https://dev.to/chromiumdev/beyond-appendchild-better-convenience-methods-for-html-55n4
function createElement(nodeName, props) {
const { style = {}, ...propsNoStyle } = props;
const element = Object.assign(document.createElement(nodeName), propsNoStyle);
for (const key in style) {
element.style[key] = style[key];
};