Join the Webstudio community

Updated 4 weeks ago

changing css trough html Embed?

i have difficulties to change a css class or id through the “html embed” and wonder if this is possible at all and what alternatives i have?
J
S
O
9 comments
What code are you using? And what does the setting of the html embed look like?
Basically I want to create a button with the html embed with which I want to show and hide an element which was built in the builder
the code would be something like that:

<button id="toggleButton" onclick="toggleVisibility()">Show</button>
<div id="test">This is the content to show or hide.</div>

<script>
function toggleVisibility() {
const testElement = document.getElementById('test');
const button = document.getElementById('toggleButton');

if (testElement.style.display === 'none') {
testElement.style.display = 'block';
button.textContent = 'Hide';
} else {
testElement.style.display = 'none';
button.textContent = 'Show';
}
}
</script>
  1. I would try a Radix component to see if there is functionality baked in already
  1. Use <script type="module">
  1. Don't use onclick, use an event listener.
  1. What do the settings of the html embed look like? Make sure client only is checked
stuff like this is likely to have broken accessibility, check radix components for this stuff
since you don't explain what exactly you are hiding/showing we can't tell what you need
I have already tried to work with the radix and the element Collapsible fits best because I want to show and hide text and pictuers underneath with a button. But I want the text of the button to change when it is clicked and that the button is detached from the collapsible content.
Can you show/describe the ux you are aiming after? I am curiuos what would be the right abstraction here
the button fades the text underneath in and out, when the button is unfolded it should say “close” in it and the arrow should be the other way around.
Attachments
Bildschirmfoto_2025-01-09_um_17.18.51.png
Bildschirmfoto_2025-01-09_um_17.18.38.png
Add a reply
Sign up and join the conversation on Discord
","upvoteCount":0,"dateCreated":"2025-01-09T15:37:01.088Z","datePublished":"2025-01-09T15:37:01.088Z","dateModified":"2025-01-09T15:37:01.088Z","url":"https://help.webstudio.is/changing-css-trough-html-embed-XCYsq7WWX1VF#b569fa15-b464-41d5-a80e-ba0ba23c115a","author":{"@type":"Person","url":"https://help.webstudio.is/members/3ebd58cc-8474-4ae7-8709-0d78b9962bad","name":"Sudi","identifier":"3ebd58cc-8474-4ae7-8709-0d78b9962bad","image":"https://cdn.discordapp.com/avatars/466605601431224340/834da08e041b7548612c50d75d65db5b.webp?size=256"}},{"@type":"Answer","text":"I would try a Radix component to see if there is functionality baked in alreadyUse