TypeError: $w(...).previous is not a function for Wix Pro Gallery

Hello.

I have a Wix Pro Gallery, in which I would like to programmatically pass the slides.
Here is the code:

$w ( "#spacesLeftArrow" ). onClick ( ( event ) => { 
    $w ( "#spacesGallery" ). next (); 
}); 
$w ( "#spacesRightArrow" ). onClick ( ( event ) => { 
    $w ( "#spacesGallery" ). previous (); 
});  

It doesn’t work in the preview, nor in the live site. But the latter prints “Uncaught (in promise) TypeError: $w(…).previous is not a function” and “Uncaught (in promise) TypeError: $w(…).next is not a function” in the console.

Any idea on how to make it work?
Thanks.

Have you put it inside

$w.onReady(() => {/*HERE*/}

?

Yes, I Have

The complete code:


$w.onReady(function () {
    // Write your JavaScript here

    $w("#spacesLeftArrow").onClick( (event) => {
        $w("#spacesGallery").next();
    });
    $w("#spacesRightArrow").onClick( (event) => {
        $w("#spacesGallery").previous();
    });

    
    // Unrelated code
    $w("#headerScroll").onViewportLeave(() => {
        $w("#clubHeaderStrip").show();
        $w("#mainHeaderStrip").hide();
    })

    $w("#headerScroll").onViewportEnter(() => {
        $w("#clubHeaderStrip").hide();
        $w("#mainHeaderStrip").show();
    })
        
    
        
});

@louvens I don’t know. If it is still doesn’t work, maybe the gallery you chose does not support .next(), previous().

And anyway, you’re better put the event handler inside the $(‘#dataset’).onReady(){} of the dataset that bound to the gallery (I don’t think it will resolve that issue though).

@jonatandor35
$(‘#dataset’).onReady(){} did not work.

I ended up using a regular slideshow gallery for the buttons to work properly.

Thanks for the help.