Error: scrollTo() Not Working in Wix Studio Repeater with Dynamic Anchor Sections

Question:
Scroll to Anchor Sections Not Working in Wix Studio with Repeater.
Can anyone help me figure out why the scrollTo() method is not working and what I might be missing in the code or setup?

Product:
Wix Studio

What are you trying to achieve:

I’m working with custom code and using a repeater where I need each button to scroll to a different section on the page. In the CMS, I have a field called anchorId with values such as dimsum_section and appetizer_section , which correspond to the anchor names of the sections I want to scroll to.

I’ve set the repeater ID to repeaterButtomNav, and the button’s ID to scrollLink , and I’m using Velo code to link each button to the corresponding anchor section. However, when I try to click a button to scroll to its assigned section, I receive the error message:

“Uncaught (in promise) TypeError: anchorElement.scrollTo is not a function.”

I’ve verified that there are no typos in the anchor names, but I’m still getting the message: “Anchor element not found or scrollTo not available.”

What have you already tried:
This is the code

$w.onReady(() => {
  $w("#repeaterButtomNav").onItemReady(($item, itemData) => {
    $item("#scrollLink").onClick(() => {
      const anchorId = itemData.anchorId;  // matches the updated anchor name in CMS
      const anchorElement = $w(`#${anchorId}`); // Scroll to the section by the updated ID
      if (anchorElement) {
        anchorElement.scrollTo(); // Scroll to the anchor element
      }
    });
  });
});

Additional information:
**My CMS setup: **

My repeater Button and anchor name:


Should be an ‘easy’ fix, but the scrollTo refers to the element ID, rather than the name given to the anchor in the inspector.

So, update the sections element IDs, and then update them in the CMS, and it should all work :slight_smile: