# onClick Collapes for anything open...

**URL:** <https://forum.wixstudio.com/t/onclick-collapes-for-anything-open/2810>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [August 10, 2018, 8:35pm UTC](https://forum.wixstudio.com/t/onclick-collapes-for-anything-open/2810 "2018-08-10T20:35:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![j4yw4lk](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j4yw4lk/32/80344_2.png) [@j4yw4lk](https://forum.wixstudio.com/u/j4yw4lk)\
**Post date:** [August 10, 2018, 8:35pm UTC](https://forum.wixstudio.com/t/onclick-collapes-for-anything-open/2810/1 "2018-08-10T20:35:42Z")

</div>

Hi,  
I’m a Wix beginner. I understand the onClick Expand/Collapse. My question is:

Is there code to make anything collapse when clicking something else?  
Example, 3 buttons show text. When clicking one button, do I need to put the code for both the other 2 buttons that would need to collapse the previous text or is there 1 piece of code that will collapse anything thats open so that it will show the new expanded text?

In otherwords, do I need code for button #1 to collapse button #2 and more code for it to close button #3? Or, is there a code to collapse anything it finds open instead of having to specify 1,2, or 3?

Thanks for anyones help 🙂

---

<div class="post-metadata">

**Author:** ![mhammouz](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mhammouz/32/4033_2.png) [@mhammouz](https://forum.wixstudio.com/u/mhammouz)\
**Post date:** [August 13, 2018, 8:27am UTC](https://forum.wixstudio.com/t/onclick-collapes-for-anything-open/2810/2 "2018-08-13T08:27:43Z")

</div>

Hi,

As you have a button, you have to clarify what should happen inside each button onClick function.

Hope this helps!  
Best,

**Mustafa**

---

<div class="post-metadata">

**Author:** ![j4yw4lk](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j4yw4lk/32/80344_2.png) [@j4yw4lk](https://forum.wixstudio.com/u/j4yw4lk)\
**Post date:** [August 13, 2018, 9:24pm UTC](https://forum.wixstudio.com/t/onclick-collapes-for-anything-open/2810/3 "2018-08-13T21:24:20Z")

</div>

Thanks Mustafa,

I get that, however… my question is do I clarify it to look for any of the other buttons that have been activated and close them down first before it activates itself? example:

when pressing button 1  
it needs to check to close button 2 and button 3

and for button 2…  
it needs to check to close button 1 and button 3?

What looking for is code to do something like this:

button 1…  
check for ANYTHING to close… instead of having to code it to check for button 2 and then check for button 3.

---

<div class="post-metadata">

**Author:** ![mqumseya](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mqumseya/32/3999_2.png) [@mqumseya](https://forum.wixstudio.com/u/mqumseya)\
**Post date:** [August 14, 2018, 10:53am UTC](https://forum.wixstudio.com/t/onclick-collapes-for-anything-open/2810/4 "2018-08-14T10:53:03Z")

</div>

Greetings,

To hide all elements of the same type you can do this:

```javascript
 $w("Image").hide(); 

```

This takes all elements on the page with the Image type and hides it.

Here is how you get the type of the element if you are confused:

```javascript
let myElement = $w("#myElement");
let elementType = myElement.type; // "$w.Type"

```

Here is some more information from the Wix API.

Best,  
Majd

---

<div class="post-metadata">

**Author:** ![j4yw4lk](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j4yw4lk/32/80344_2.png) [@j4yw4lk](https://forum.wixstudio.com/u/j4yw4lk)\
**Post date:** [August 23, 2018, 5:47pm UTC](https://forum.wixstudio.com/t/onclick-collapes-for-anything-open/2810/5 "2018-08-23T17:47:12Z")

</div>

Hi Majid,

I’m still having issues understanding. Is there any way you can take time to walk me though what I need done, please?
