Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Last active October 8, 2018 01:09
Show Gist options
  • Select an option

  • Save davidgilbertson/432a0fe2dafb778f0cb56e214ece4f4d to your computer and use it in GitHub Desktop.

Select an option

Save davidgilbertson/432a0fe2dafb778f0cb56e214ece4f4d to your computer and use it in GitHub Desktop.
function makeElement(type, props, text) {
const el = document.createElement(type);
Object.keys(props).forEach(prop => {
el[prop] = props[prop];
});
const textNode = document.createTextNode(text);
el.appendChild(textNode);
return el;
}
const h1 = (...args) => makeElement(`h1`, ...args);
// and then ...
document.body.appendChild(
h1(
{ className: `title` },
`Hello, world.`,
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment