Skip to content

Instantly share code, notes, and snippets.

@nickytonline
Last active December 11, 2024 01:13
Show Gist options
  • Save nickytonline/8223b27b19c080c28d9f0d3b7fce1e82 to your computer and use it in GitHub Desktop.
Save nickytonline/8223b27b19c080c28d9f0d3b7fce1e82 to your computer and use it in GitHub Desktop.

Revisions

  1. nickytonline revised this gist Dec 10, 2024. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions createElement.js
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,10 @@
    function createElement(nodeName, props) {
    const { style = {}, ...propsNoStyle } = props;
    const element = Object.assign(document.createElement(nodeName), propsNoStyle);

    Object.entries(style).forEach(([key, value]) => { element.style[key] = value; });

    for (const key in style) {
    element.style[key] = style[key];
    };

    return element;
    }
  2. nickytonline renamed this gist Jul 11, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. nickytonline created this gist Jul 11, 2019.
    10 changes: 10 additions & 0 deletions createElement
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    // 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);

    Object.entries(style).forEach(([key, value]) => { element.style[key] = value; });

    return element;
    }