# Why doesn't this container collapse?

**URL:** <https://forum.wixstudio.com/t/why-doesnt-this-container-collapse/70160>\
**Category:** Ask the community\
**Tags:** wix-storage-frontend, question, wix-studio, code\
**Created:** [April 6, 2025, 11:01pm UTC](https://forum.wixstudio.com/t/why-doesnt-this-container-collapse/70160 "2025-04-06T23:01:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koen\_Stewart](https://avatars.discourse-cdn.com/v4/letter/k/57b2e6/32.png) [@Koen\_Stewart](https://forum.wixstudio.com/u/Koen_Stewart)\
**Post date:** [April 6, 2025, 11:01pm UTC](https://forum.wixstudio.com/t/why-doesnt-this-container-collapse/70160/1 "2025-04-06T23:01:14Z")

</div>

Hey, so I’m having some issues with collapsing containers. When clicking the X as a first-time visitor, it works just as it should and collapses the container. However, when refreshing the page, the container should remain hidden, but it doesn’t. Any ideas why? I also tried logging the `hideUntil` constant, but it didn’t work. The container is set in the properties panel has collapsed to avoid a flash before hiding when the code is loading. See the code below ([www.cmmba.org](http://www.cmmba.org)). TIA.

```javascript
import { local } from 'wix-storage-frontend';

$w.onReady(async function () {
    // Check if the container should be hidden
    const hideUntil = local.getItem('hideTrailforksOfferUntil');
    console.log(hideUntil);
    if (hideUntil && new Date(hideUntil) > new Date()) {
        $w('#trailforksBanner').collapse();
    } else {
        $w('#trailforksBanner').expand();
    }

    // Set up the button click event
    $w('#trailforksBannerCloseButton').onClick(async () => {
        // Hide the container
        $w('#trailforksBanner').collapse();

        // Set the flag to hide the container for 2 weeks
        const twoWeeksFromNow = new Date();
        twoWeeksFromNow.setDate(twoWeeksFromNow.getDate() + 14);
        local.setItem('hideTrailforksOfferUntil', twoWeeksFromNow.toISOString());
    });
});

```

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [April 7, 2025, 2:23am UTC](https://forum.wixstudio.com/t/why-doesnt-this-container-collapse/70160/2 "2025-04-07T02:23:35Z")

</div>

Hi, @Koen_Stewart !!

I tried your code, and the container was able to collapse properly. The log shows “2025-04-21T02:01:39.379Z”. I replaced `local` with `session` in the code, but I don’t think that fundamentally changed anything. 🙃

---

<div class="post-metadata">

**Author:** ![onemoretime](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/onemoretime/32/104023_2.png) [@onemoretime](https://forum.wixstudio.com/u/onemoretime)\
**Post date:** [April 7, 2025, 2:29am UTC](https://forum.wixstudio.com/t/why-doesnt-this-container-collapse/70160/3 "2025-04-07T02:29:41Z")

</div>

It’s possible that an error occurred earlier in the code before reaching the part that triggers the collapse, preventing it from executing properly. As a test, try doing the same thing on a fresh, blank page. 🤔

---

<div class="post-metadata">

**Author:** ![V-Blog](https://avatars.discourse-cdn.com/v4/letter/v/898d66/32.png) [@V-Blog](https://forum.wixstudio.com/u/V-Blog)\
**Post date:** [April 7, 2025, 6:29am UTC](https://forum.wixstudio.com/t/why-doesnt-this-container-collapse/70160/4 "2025-04-07T06:29:28Z")

</div>

Try following code. It stores the hidden state of your container. This will make sure that the banner stays hidden. To make it reappear, visitors will have to clear the website’s cookies. Right now, it is hidden for two weeks but you can set it to days, hours, or minutes as well. I haven’t tested it but it should work.

Hope It helps

🙂

```javascript
import { local } from 'wix-storage-frontend';

$w.onReady(async function () {
    const hideUntil = local.getItem('hideTrailforksOfferUntil');
    console.log('hideUntil from storage:', hideUntil); 

    const currentDate = new Date();
    const hideUntilDate = hideUntil ? new Date(hideUntil) : null;
    console.log('Parsed hideUntilDate:', hideUntilDate); 
    console.log('Current date:', currentDate); 

    if (hideUntilDate && hideUntilDate > currentDate) {
        $w('#trailforksBanner').collapse();
    } else {
        $w('#trailforksBanner').expand();
        if (hideUntilDate && hideUntilDate <= currentDate) {
            local.removeItem('hideTrailforksOfferUntil');
            console.log('Expired hideUntil cleared from storage');
        }
    }

    $w('#trailforksBannerCloseButton').onClick(async () => {
        $w('#trailforksBanner').collapse();

        const twoWeeksFromNow = new Date();
        twoWeeksFromNow.setDate(twoWeeksFromNow.getDate() + 14);
        const hideUntilValue = twoWeeksFromNow.toISOString();
        local.setItem('hideTrailforksOfferUntil', hideUntilValue);
        console.log('Set hideUntil to:', hideUntilValue); 
    });
});

```
