[SOLVED] Making a button that can be clicked more than once

So, I had made a collection and connected it to a dataset and gallery. I implemented a code so that each time the viewer refreshes the page, the images in the gallery get shuffled. That worked out fine. I thought I would also add a button that would shuffle the images without having to refresh the page. However, I am having trouble with the coding.

This code works but the button can only be clicked once due to the onClick:

$w . onReady ( function () {

$w ( ‘#button2’ ). onClick (()=>{
$w ( “#dataset1” ). refresh ();
});
});

So I was wondering if there was a way to override the onClick or something so that the button can be clicked over and over again? I’m very very new to web design and coding but would appreciate some help!

This is what I used for shuffling the gallery:

$w . onReady ( function () {
$w ( “#dataset1” ). onReady (() => {
let items = $w ( “#gallery1” ). items ;
items = shuffle ( items );
$w ( “#gallery1” ). items = items ;
});
});
export function shuffle ( array ) {
for ( let i = array . length - 1 ; i > 0 ; i – ) {
const j = Math . floor ( Math . random () * ( i + 1 ));
[ array [i], array [j]] = [ array [j], array [i]];
}

return array ;
}

$w.onReady(() => {
$w("#dataset1").onReady(() => {
       shuffleAndBind();
       $w('#button2').onClick(shuffleAndBind);
    });
})

function shuffleAndBind() {
let items = $w("#gallery1").items;
for (let i = items.length - 1; i > 0; i--) {
   const j = Math.floor(Math.random() * (i + 1));
   [items[i], items[j]] = [items [j], items[i]];
}
$w("#gallery1").items = items;
}

Oh my gosh it works! Bless your kind soul! I really appreciate it :smiley: