# Show/Hide elements on button click

**URL:** <https://forum.wixstudio.com/t/show-hide-elements-on-button-click/11169>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 19, 2023, 2:08am UTC](https://forum.wixstudio.com/t/show-hide-elements-on-button-click/11169 "2023-05-19T02:08:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mm-tyfl](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mm-tyfl/32/24708_2.png) [@mm-tyfl](https://forum.wixstudio.com/u/mm-tyfl)\
**Post date:** [May 19, 2023, 2:08am UTC](https://forum.wixstudio.com/t/show-hide-elements-on-button-click/11169/1 "2023-05-19T02:08:00Z")

</div>

Hi, I’ve read many other similar posts on this but it doesn’t seem to work for me. Here’s what I’m trying to do…  
I am trying to make a text box to replace the original text on page load when I click a button. Clicking another button on the page will replace that text to show another text box.  
e.g. When I click #rescueButton, #rescueText will appear, #animalServicesText will be hidden. The button will then change it’s fill colour. (I created a duplicate button, #rescueButtonSelected for this)

My current code is:

export function rescueButton\_click ( event ) {  
let isHidden = $w ( “#rescueText” ). hidden ; // false  
if ( $w ( “#rescueText” ). hidden ) {  
$w ( “#rescueText” ). show ();  
$w ( “#rescueButtonSelected” ). show ();  
$w ( “#animalServicesText” ). hide ();  
}  
**else** {  
$w ( “#rescueText” ). hide ();  
$w ( “#rescueButtonSelected” ). hide ();  
$w ( “#animalServicesText” ). show ();  
}  
}

Right now, nothing happens when I run this code. Am I missing anything?

Thank you in advance for any help!

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [May 19, 2023, 4:29am UTC](https://forum.wixstudio.com/t/show-hide-elements-on-button-click/11169/2 "2023-05-19T04:29:41Z")

</div>

```javascript
$w.onReady(()=>{
	$w('#rescueButton').onClick(()=>{
		if($w("#rescueText").hidden) {
			$w("#rescueText").show();
			$w("#rescueButtonSelected").show();
			$w("#animalServicesText").hide();
		}
		else{
			$w("#rescueText").hide();
			$w("#rescueButtonSelected").hide();
			$w("#animalServicesText").show();
		}
	});	
});

```

---

<div class="post-metadata">

**Author:** ![mm-tyfl](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mm-tyfl/32/24708_2.png) [@mm-tyfl](https://forum.wixstudio.com/u/mm-tyfl)\
**Post date:** [May 19, 2023, 5:45am UTC](https://forum.wixstudio.com/t/show-hide-elements-on-button-click/11169/3 "2023-05-19T05:45:37Z")

</div>

Thank you Code-Ninja for this. It has worked brilliantly for the first button! However, I have three buttons, is there a way for it to show another textbox when a second button, #transportButton, is clicked and so on?

is there a way to also hide the text if I click the respective highlighted button again?

e.g.  
Click #rescueButton, show #rescuetext and #rescueButtonSelected  
Click #transportButton, show #transportText and #transportButtonSelected  
Click #husbandryButton, show #husbandryText and #husbandryButtonSelected

then if I click #rescueButtonSelected (after I clicked #rescueButton), then it hides #rescuetext and so on…

---

<div class="post-metadata">

**Author:** ![gallw-asingeborg](https://avatars.discourse-cdn.com/v4/letter/g/dc4da7/32.png) [@gallw-asingeborg](https://forum.wixstudio.com/u/gallw-asingeborg)\
**Post date:** [May 22, 2023, 5:27am UTC](https://forum.wixstudio.com/t/show-hide-elements-on-button-click/11169/4 "2023-05-22T05:27:27Z")

</div>

Thanks for this solution. [**https://www.cfa-home.net/**](https://www.cfa-home.net/)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [May 24, 2023, 12:46pm UTC](https://forum.wixstudio.com/t/show-hide-elements-on-button-click/11169/5 "2023-05-24T12:46:13Z")

</div>

In a simple COPY and PASTE CODING…

```javascript
$w.onReady(()=>{
    //Rescue-Button
    $w('#rescueButton').onClick(()=>{
        if($w("#rescueText").hidden) {
            $w("#rescueText").show();
            $w("#rescueButtonSelected").show();
            $w("#animalServicesText").hide();
        }
        else{
            $w("#rescueText").hide();
            $w("#rescueButtonSelected").hide();
            $w("#animalServicesText").show();
        }
    }); 

    //Transport-Button...
    $w(' #transportButton').onClick(()=>{
        if($w("#transportText").hidden) {
            $w("#transportText").show();
            $w("#transportButtonSelected").show();
            $w("#animalServicesText").hide();
        }
        else{
            $w("#transportText").hide();
            $w("#transportButtonSelected").hide();
            $w("#animalServicesText").show();
        }
    }); 

    //Husbandry-Button...
    $w('#husbandryButton').onClick(()=>{
        if($w("#husbandryText").hidden) {
            $w("#husbandryText").show();
            $w("#husbandryButtonSelected").show();
            $w("#animalServicesText").hide();
        }
        else{
            $w("#husbandryText").hide();
            $w("#husbandryButtonSelected").hide();
            $w("#animalServicesText").show();
        }
    }); 
});

```
