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


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?

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("#spacesRightArrow").onClick( (event) => {

    // Unrelated code
    $w("#headerScroll").onViewportLeave(() => {

    $w("#headerScroll").onViewportEnter(() => {

@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).

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

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

Thanks for the help.