Set Element Text On Click
A simple example of how to use htmgo with javascript
package snippets
import (
"github.com/maddalax/htmgo/framework/h"
"github.com/maddalax/htmgo/framework/js"
)
func SetTextOnClick(ctx *h.RequestContext) *h.Partial {
return h.NewPartial(
h.Button(
h.Text("Click to set text"),
h.Class("bg-slate-900 text-white py-2 px-4 rounded"),
h.OnClick(
js.SetText("Hello World"),
),
),
)
}
Copy
1package snippets
2
3import (
4 "github.com/maddalax/htmgo/framework/h"
5 "github.com/maddalax/htmgo/framework/js"
6)
7
8func SetTextOnClick(ctx *h.RequestContext) *h.Partial {
9 return h.NewPartial(
10 h.Button(
11 h.Text("Click to set text"),
12 h.Class("bg-slate-900 text-white py-2 px-4 rounded"),
13 h.OnClick(
14 js.SetText("Hello World"),
15 ),
16 ),
17 )
18}