Show hidden bloc

Hello, in a bloc I have 3 buttons, named “A”, “B” and “C”. When I click on the button “A”, only the hidden bloc “A” should be displayed. When I click on button “B”, only the hidden bloc “B” should be displayed and when I click on button “C”, only the hidden bloc “C” should be displayed. I didn’t get the desired result with “Toggle Visibility”.

Hi:

Got a link?

Rich the Weather Guy

@WeatherguyNH Hello, it’s only an idea. May be I just found the answer here: https://forum.blocsapp.com/t/to-toggle-and-to-hide-visibility-of-some-blocs/3724

1 Like

One good way would be to use a switch statement in the javascript. then just set the parameter to what you need to show. Let me know if you need further explanation or a sample.

@cincyplanet … So far I haven’t found a solution to my problem. So I look forward to more from you. Thank you very much.

This is just off the top of my head but try something like this;

create a function like:

function setVisible(mynumber){

document.getElementById(“A”).style.display === “none”;
document.getElementById(“B”).style.display === “none”;
document.getElementById(“C”).style.display === “none”;

switch (mynumber) {
case 0:
document.getElementById(“A”).style.display === “none”;
break;
case 1:
document.getElementById(“B”).style.display === “none”;
break;
case 2:
document.getElementById(“C”).style.display === “none”;
break;
}

}

then in the action for the button just call which one you want to turn on:
setVisible(0)

So in the function:
0 = A
1 = B
2 = C

@cincyplanet oh, thanks for your support. I’ll try asap and then report.

No problem

They don’t need a comparison operator, so something like this…

document.getElementById(“A”).style.display = “none”;

And this one ….

I would either set display to an empty string “ ” or block or flex etc.


document.getElementById(“A”).style.display = “block”;

Another method is to run an event listener with a target class, makes it easier to add or remove additional elements to your content without having to change any code. But the suggested method above works well.

Pete good catch, that what I get doing it off the top of my head lol

1 Like