diff --git a/htmgo-site/md/docs/4_interactivity/2_events.md b/htmgo-site/md/docs/4_interactivity/2_events.md index 809cf9e..ff23731 100644 --- a/htmgo-site/md/docs/4_interactivity/2_events.md +++ b/htmgo-site/md/docs/4_interactivity/2_events.md @@ -91,3 +91,15 @@ func MyButton() *h.Element { } ``` +tip: If you are using Jetbrains IDE's, you can write `// language=js` as a comment above the function call (h.EvalJS) and it will automatically give you syntax highlighting on the raw JS. + +```go +// language=js +h.EvalJs(` + if(Math.random() > 0.5) { + self.innerHTML = "Success!"; + } + `, +), +``` + diff --git a/htmgo-site/pages/index.go b/htmgo-site/pages/index.go index 0aad8e1..aee2dcf 100644 --- a/htmgo-site/pages/index.go +++ b/htmgo-site/pages/index.go @@ -5,6 +5,21 @@ import ( "htmgo-site/pages/base" ) +func Test() *h.Element { + return h.Button( + h.Text("Submit"), + h.OnClick( + // language=js + h.EvalJs(` + if(Math.random() > 0.5) { + self.innerHTML = "Success!"; + } + `, + ), + ), + ) +} + func IndexPage(ctx *h.RequestContext) *h.Page { return h.NewPage( base.RootPage(h.Div( @@ -29,6 +44,7 @@ func IndexPage(ctx *h.RequestContext) *h.Page { ), ), ), + Test(), h.Div( h.Class("border-b border-b-slate-200 h-1"), h.Div(