Buttons to show and hide gallery

Hello all, I thought this code would work, but seemingly I have it so very very wrong! Please note I am not all that familiar with code, this was copied from elsewere.

Scenario: I have a page, I want to use buttons to hide and show galleries respectively (2 galleries) Each gallery draws data from a different dataset (2 datasets on the page)

When the page loads #gallery1 is visible (Yay) then using the buttons i want to hide #gallery1 and show #gallery2…what am I missing from the below?

Many thanks in advance.
$w . onReady ( function () {

$w ( '#gallery1' ). show (), $w ( '#gallery2' ). hide ();  

});

export function button2_click ( event ) {

$w ( '#gallery2' ). show (), $w ( '#gallery1' ). hide (); 

}

export function button1_click ( event ) {

$w ( '#gallery1' ). show (), $w ( '#gallery2' ). hide (); 

}

Hi Carlie,

The code seems fine for most parts.
The only thing you did that should not be done is adding them on 1 line seperated with a comma.

So use it like this:


export function button1_click(event){
$w('#gallery1').show();
$w('#gallery2').hide();
}

This should work :slight_smile:

Kind regards,
Kristof.

Thank you so much for your reply. I have changed it as per your instruction. It still doesn’t work.

Am I right in thinking that buttons are executed via the code not through attaching them to a dataset or other links?

I’m not sure if it makes any difference how the galleries are populated? Whilst both use a dataset, one gallery uses multiple individual images from separate entries within a collection
The other uses a media gallery.

Its a wixpro gallery?

I’ve attached a snap, i’ve just slapped the galleries one over the other so you can see that there are 2. Buttons are also labelled as the code suggests =(

@cjdretouch
The code seems fine now,
Are onClick events still linked to the buttons?
Click on the button (in the editor)
and check the event handlers at the right.


If there isn’t anything at where the green text is, then your button is not connected to the onClick function.

Kind regards,
Kristof.

@volkaertskristof Oooh this is exciting, bear with me, this is what I have… and thank you!

@cjdretouch
Oke so evrything is fine as it should be, but it still ain’t working?

If you would like, i can always take a look at your website,
You can make a copy of it ( so i can’t screw up the existing website) and add me as a contributor “kristof.print3d@gmail.com

This way i can check and maybe see where it goes wrong.

Note: I’m not a wix Employee or connected to wix in any way :slight_smile:

Kind regards,
Kristof

@volkaertskristof I FOUND IT! you’re an absolute legend! i could cry… I didnt have the other button linked. You’re a genious! I’m so grateful you have no idea how hard i’ve been aggonising over this ridiculously simple code. Thank you.ssoooooo much =)

Aah thats great!
Happy i could help :slight_smile:

Kind regards,
Kristof

Can you share what was done to resolve this