Comment by marwis
3 years ago
You can do it with custom elements, e.g.
<dom-calc>
const p = document.createElement('button');
p.innerText = 'hi';
p.onclick = () => alert('hi');
return p;
</dom-calc>
For something like:
class CalcElement extends HTMLElement {
connectedCallback() {
setTimeout(() => {
const fn = new Function(this.innerText);
this.replaceWith(fn());
}, 0);
}
}
customElements.define('dom-calc', CalcElement);
No comments yet
Contribute on Hacker News ↗