tipsy / j2html

Java to HTML generator. Enjoy typesafe HTML generation.

Home Page:https://j2html.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: javascript and common events

Delta-38 opened this issue · comments

I might be missing the point, but I didn't see it the examples section.
What is the recommended approach with j2html for common DOM events?
Such as onclick, onhover etcetera
I find that I can achieve that with attr(name,value) but it doesn't show up intuitively (or rather I find myself trying lots of things before remembering.

Thanks in advance for creating such a fun library to work with in any case.

commented

Hi! J2html is just for creating html, I recommend you keep your Javascript in a separat file and include it via a script tag.

commented

Try HTMX.

I got here by searching exactly for this same, I think it does makes sense to have on click for buttons, as is it is still achievable to add them using the following syntax

button().attr("onClick=console.log('hi')")

Non the less having something as:

button().onClick("console.log('hi')")

would be nice preventing typos at least on the on click part and also facilitating using reflection to build html on the fly calling certain functions.

I also agree that js should be separate yet the calling to it can be done on HTML, this way preventing the need of having to do the linking on JS itself