Help with hello world
icetbr opened this issue · comments
Hi there, I can't get this to work. The esm version runs fine.
<script src="https://unpkg.com/uhtml">
const { render, html } = uhtml;
render(document.body, html`<h1>Hello µhtml</h1>`);
</script>
Tried both firefox and chrome latest versions, both through file:// and a node created local server
that's because esm uses module which runs when document.body is known ... you need to use DOMContentLoaded event otherwise if you just trash this on a page because document.body doesn't exist when this synchronous script runs.
Thank you. For reference, here is the working version.
<script src="https://unpkg.com/uhtml"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
const { render, html } = uhtml;
render(document.body, html`<h1>Hello µhtml</h1>`);
});
</script>