Archived topic
how to use a button to display or hide content
3 replies · Started by Dennis on July 27, 2022
Hello, I'd like to use a button similar to the one displayed in the page attached, that toggles between individual and couple, and then immediately displays the correct price. Can i do that with GeneratePress Premium or GenerateBlocks and if so could you give me direction on that?
I found a plugin called toggle-content but naturally would prefer to avoid another plug-in if not needed.
Thanks! Dennis
Hi there,
This isn't something GP/GB can do by default so it will require a custom solution.
If the plugin you found works for you then I'd say that's the best method.
Hope this helps :)
Hi Leo, thank you. Before I move to the plugin, I've attached the page I'm working on (draft) to be more specific about my question. There are 2 actions I'm needing helping with.
First, I would want the 2 buttons (for Individual and Couple) to only allow one button to be selected at a time.
Second, the button that is selected would display the particular container relevant to that button. For example, selecting Individual would display a particular container ; clicking on the Couple button would deselect the Individual button and then display a different container.
I kept looking and found this method that seems to allow for toggling displayed text on or off...could that help here?
Thanks! Dennis
Hi Dennis,
Yes, this can be done through JS code, though this would be out of our scope. You could try looking for a plugin as well.
Basically, if through JS code, you’ll need to create an onclick event for the button to add a class to your containers. So, if “Individual” is selected, add “display” class to container-1 and remove “display” class for container-2 for instance. Vis versa for the Couple button.
Personally, it might be better to code this than to use a Plugin if it’s that simple.