Collapse Element on Page Load

How can I hide or collapse and element on page load but still have it show via a button on click?

Hey there citisonship,

Collapse the element (e.g. table) in the onReady function:

$w.onReady(function () {
	$w("#table1").collapse();
});

And then add an onClick routine for your button:

And fill in the onClick routine to toggle between expand and collapse:

export function button1_click(event, $w) {
	if($w("#table1").collapsed) {
		$w("#table1").expand();
	}
	else {
		$w("#table1").collapse();
	}
}

I hope this helps.

Yisrael

Perfect Thanks! I had one thing wrong:)

Hi Yisrael,

Sorry I am late to the party. Quick question, I have used the above code and it works brilliantly thanks :slight_smile: but it doesn’t work on either android HTC U11 using Android 8.0.0 or Lenovo Tab A10-70F using
Android 6.0
The table is “collapsed on load” box is checked within the desktop editor BUT when you switch to view the mobile - the table is “collapsed on load” box is UNchecked - when you view the live site on the phone a blank table appears.
However,
When you view the page on my tablet - the table is NOT visible - BUT when you fill our the search criteria and press the “GO” button NOTHING happens ??
Is it me - or am I missing something?


Here’s the URL : https://victoriashelley200.wixsite.com/ask-us

I would be grateful of any help -thanks so much :slight_smile:

P.s. I have just discovered that if I turn off the mobile optimization - IT WORKS !! on the tablet perfectly - but obviously the mobile doesn’t look that great - sigh!!

Hey Victoria,

Glad you got it worked out.

When in mobile mode in the Editor, you can edit the screens yourself so that they look nicer. The built-in mobile optimization is a “best attempt” and not a “best result”. It often does the job just fine, but there are times where it just can’t read the users mind. :upside_down_face:

You might want to check with the Wix support team , as they might have more information for you.

Good luck and have fun,

Yisrael

Thanks Yisrael. It was a bug and wix support got it fixed.