# Collapsable Elements code

**URL:** <https://forum.wixstudio.com/t/collapsable-elements-code/26180>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 11, 2018, 11:37pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180 "2018-03-11T23:37:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel-martins](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/daniel-martins/32/2477_2.png) [@daniel-martins](https://forum.wixstudio.com/u/daniel-martins)\
**Post date:** [March 11, 2018, 11:37pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/1 "2018-03-11T23:37:46Z")

</div>

Hello everyone! i have just been introduced to code and i am trying to make a collapsable menu using this wix tutorial [https://www.wix.com/code/home/example/Collapse-Elements](https://www.wix.com/code/home/example/Collapse-Elements)  
However when i apply it to my website i get an error saying “index is undefined”.  
The code i have is this

$w.onReady(function () {  
//TODO: function toggleFold(index) {  
let $fold = $w(‘#fold’ + index);  
let $arrowDown = $w(‘#arrowDown’ + index);  
let $arrowRight = $w(‘#arrowRight’ + index);  
// toggle the fold at the index  
if ($fold.collapsed) {  
$fold.expand();  
$arrowDown.show();  
$arrowRight.hide();  
}  
else {  
$fold.collapse();  
$arrowDown.hide();  
$arrowRight.show();  
}  
// collapse the other folds  
[1,2,3,4]  
.filter(idx =\> idx !== index)  
.forEach(idx =\> {  
$w(‘#fold’ + idx).collapse();  
$w(‘#arrowDown’ + idx).hide();  
$w(‘#arrowRight’ + idx).show();  
})  
}

);

export function vectorImage1\_click(event, $w) {$w(“#group2”).show();  
//Add your code for this event here:  
}

How can i solve this ? 🙂

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [March 12, 2018, 7:15am UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/2 "2018-03-12T07:15:43Z")

</div>

Seems to me that instead of:

```javascript
$w.onReady(function () {
	//TODO: function toggleFold(index) {

```

You need:

```javascript
function toggleFold(index) {

```

Notice that the function statement declared index as a parameter.

Refer to the Collapse Elements example for the full code.

I hope this helps.

Yisrael

---

<div class="post-metadata">

**Author:** ![nschanstudio](https://avatars.discourse-cdn.com/v4/letter/n/7bcc69/32.png) [@nschanstudio](https://forum.wixstudio.com/u/nschanstudio)\
**Post date:** [August 5, 2018, 3:47pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/3 "2018-08-05T15:47:04Z")

</div>

Hi Yisreal, I followed exactly the same code as the example from Wix and renamed every item with the same id naming. But when i preview it on the page, the box did not expand, the down arrow did not appear, and i got a message that in order to debug, i need to open masterPage.js and Ob0ee.js, of which these 2 I do not have unless I create them myself but I also not sure what am i supposed to add in these 2 js?

---

<div class="post-metadata">

**Author:** ![nschanstudio](https://avatars.discourse-cdn.com/v4/letter/n/7bcc69/32.png) [@nschanstudio](https://forum.wixstudio.com/u/nschanstudio)\
**Post date:** [August 5, 2018, 4:33pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/4 "2018-08-05T16:33:22Z")

</div>

Ok. I finally solved it! Reason is because we **cannot fully copy the example in Wix Code example**.  
The autogenerated **onclick event has different naming in our current editor page**. See image below. And we cannot edit that naming. So I need to change the “\_onClick” in the code to “\_click”. Then everything works just fine. Probably Wix needs to update this change.

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/0/d0a364df5782f22ad6e62e6ecaacb6977eac2f05.jpeg)

---

<div class="post-metadata">

**Author:** ![yvonne088](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yvonne088/32/9778_2.png) [@yvonne088](https://forum.wixstudio.com/u/yvonne088)\
**Post date:** [March 7, 2019, 12:19am UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/5 "2019-03-07T00:19:36Z")

</div>

Hi, I’m so glad you solved it! I am trying to add a collapsable element to my website as well. However, i copied these codes and pasted them onto my page in Wix Codes, but absolutely nothing shows.

What am I missing here? I would greatly appreciate any help! Thanks.

---

<div class="post-metadata">

**Author:** ![nschanstudio](https://avatars.discourse-cdn.com/v4/letter/n/7bcc69/32.png) [@nschanstudio](https://forum.wixstudio.com/u/nschanstudio)\
**Post date:** [March 7, 2019, 4:57am UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/6 "2019-03-07T04:57:21Z")

</div>

Hi Yvonne, you cannot just copy these codes. As explained in my post, the codes from Wix is outdated. You need to check the coding for any “\_onclick” naming and change to “\_click”. Hope this clarifies.

---

<div class="post-metadata">

**Author:** ![yvonne088](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yvonne088/32/9778_2.png) [@yvonne088](https://forum.wixstudio.com/u/yvonne088)\
**Post date:** [March 11, 2019, 9:56pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/7 "2019-03-11T21:56:50Z")

</div>

@nschanstudio I changed “\_onclick” to “\_click” and did some more research but the code is still not expanding my collapsed box. Here is my code:

**function** toggleFold(index) {  
**let** $fold = $w(‘#fold’ + index);  
**let** $arrowDown = $w(‘#arrowDown’ + index);  
**let** $arrowRight = $w(‘#arrowRight’ + index);  
// toggle the fold at the index  
**if** ($fold.collapsed) {  
$fold.expand();  
$arrowDown.show();  
$arrowRight.hide();  
}  
**else** {  
$fold.collapse();  
$arrowDown.hide();  
$arrowRight.show();  
}  
// collapse the other folds  
[1,2,3,4]  
.filter(idx =\> idx !== index)  
.forEach(idx =\> {  
$w(‘#fold’ + idx).collapse();  
$w(‘#arrowDown’ + idx).hide();  
$w(‘#arrowRight’ + idx).show();  
})  
}

export function headerBox1\_Click(event) {  
toggleFold(1);  
}

export function headerBox2\_Click(event) {  
toggleFold(2);  
}

Any advice would be greatly appreciated!

Thanks again,

Yvonne

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [March 11, 2019, 10:53pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/8 "2019-03-11T22:53:15Z")

</div>

@yvonne088 You state: _I changed “\_onclick” to “\_click”_ but your functions have \_Click, not \_click. Could this be your problem?

---

<div class="post-metadata">

**Author:** ![yvonne088](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yvonne088/32/9778_2.png) [@yvonne088](https://forum.wixstudio.com/u/yvonne088)\
**Post date:** [March 11, 2019, 11:25pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/9 "2019-03-11T23:25:14Z")

</div>

@yisrael-wix You are seriously a hero - it works now! Thank you so much for taking the time to help me out, I really appreciate it.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [March 11, 2019, 11:48pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/10 "2019-03-11T23:48:13Z")

</div>

@yvonne088 Glad to hear. I’ll buy a cape tomorrow.

---

<div class="post-metadata">

**Author:** ![nschanstudio](https://avatars.discourse-cdn.com/v4/letter/n/7bcc69/32.png) [@nschanstudio](https://forum.wixstudio.com/u/nschanstudio)\
**Post date:** [March 12, 2019, 2:03pm UTC](https://forum.wixstudio.com/t/collapsable-elements-code/26180/11 "2019-03-12T14:03:08Z")

</div>

@yisrael-wix glad you solved it with the help of others. yes it is THAT case sensitive. I really hope Wix can really update its code as soon as possible.
