Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: javascript and common events #137

Open
Delta-38 opened this issue Sep 3, 2019 · 3 comments
Open

Question: javascript and common events #137

Delta-38 opened this issue Sep 3, 2019 · 3 comments
Labels

Comments

@Delta-38
Copy link

Delta-38 commented Sep 3, 2019

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.

@tipsy
Copy link
Owner

tipsy commented Sep 13, 2019

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

@jankod
Copy link

jankod commented Sep 1, 2021

Try HTMX.

@Ordiel
Copy link

Ordiel commented Jun 7, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants