neverstew-htmxexample.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/** @jsxImportSource https://esm.sh/preact */
import { html } from "https://esm.town/v/neverstew/html";
import { Hono } from "npm:hono";
export const htmxExample = async (request: Request): Promise<Response> => {
const app = new Hono();
app.get("/", (c) =>
c.html(html(
<>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/water.css" />
<script
src="https://unpkg.com/htmx.org@1.9.4"
integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV"
crossorigin="anonymous"
>
</script>
<title>My Val Town Page</title>
</head>
<body>
<main>
<h1>My list</h1>
<ol id="list">
<button
hx-get="/items/new"
hx-target="#list"
hx-swap="beforeend"
>
Add item
</button>
<button
hx-get="#"
hx-target="next li"
hx-swap="delete"
>
Remove item
</button>
</ol>
</main>
</body>
</>,
)));
app.get("/items/new", (c) =>
c.html(html(
<li>
<p>New item</p>
</li>,
)));
return app.fetch(request);
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v23
October 23, 2023