Skip to content

Instantly share code, notes, and snippets.

@disjukr
Last active August 29, 2015 14:26
Show Gist options
  • Save disjukr/90abba4966d79d2942f7 to your computer and use it in GitHub Desktop.
Save disjukr/90abba4966d79d2942f7 to your computer and use it in GitHub Desktop.
super simple dom template function

el

super simple dom template function

how to use

screenshot

function el(qs, ...children) {
let m = qs[0].match(/([^#\.]+)?(?:#([^\.]+))?(?:\.(.+))?/);
let el = document.createElement(m[1] || 'div');
let id = m[2]; if (id) el.id = id;
let cls = m[3]; if (cls) el.className = cls.replace(/\./g, ' ');
for (let child of children) {
el.appendChild(
typeof child === 'string' ?
document.createTextNode(child) :
child
);
}
return el;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment