loading...
Cover image for A createElement one-liner (with attributes and children)

A createElement one-liner (with attributes and children)

yne profile image Rémy F. ・1 min read

The one-liner

el = (tag, props={}, ch=[]) => ch.reduce((e,c) => (e.appendChild(c),e),Object.assign(document.createElement(tag),props))

Usage

el('ul',{classList:['list']},[
  el('li',{innerText:'first'}),
  el('li',{innerText:'second'}),
])

have a nice day

Discussion

pic
Editor guide