Replies: 1 comment
-
From what I saw, you are trying to use the First, let's tweak the code to ensure the toggleClass function is correct and called properly in the component:
If the My complete example looked like this:
If you liked it, follow me :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
currently doing a barebones project to find out the capabilities of templ. Building some components and ran into the following problem:
I added this script to my templ file:
script toggleClass(id string) { document.getElementById(id).classList.toggle("toggled"); }
It is used in the component button onClick as follows:
<button onClick={ toggleShow("toggleClass")) }>{ title }</button>
Following the documentation of the toggle it should add the class to the element with the passed id if it is not there else it should remove it -> return value of the function represents the respective boolean value. This is not the case, it will always return true but it wont add the class to the element. It is not an issue with the JS code as it is working fine in the browser console.
Are there any specifics on how this kind of JS script/ dom manipulation are approached in templ?
Appreciate any help
Cheers.
Beta Was this translation helpful? Give feedback.
All reactions