|
|
|
|
|
by wolfgang42
1216 days ago
|
|
An even simpler bit of sugar over the DOM that I embed whenever I need just a little bit of JS: function $E(t,p,c) {
const el=document.createElement(t)
Object.assign(el,p)
el.append(...c)
return el
}
Usage: const button = $E('button', {onclick: () => alert('click!')}, [
$E('img', {src: '/assets/icon-lightbulb.png'}, []),
'Ding!',
])
(With thanks to 'goranmoomin: https://news.ycombinator.com/item?id=23590750) |
|
parent.append(<p>Hello</p>);
(Mine has slightly more functionalities, such as allowing passing in styles as a object, auto concatenate array of strings for class names, etc.)