# Navigating to an anchor in mobile

**URL:** <https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 25, 2022, 5:50pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168 "2022-12-25T17:50:03Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cue](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cue](https://forum.wixstudio.com/u/Cue)\
**Post date:** [December 25, 2022, 5:50pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/1 "2022-12-25T17:50:03Z")

</div>

Please how do I navigate to anchors in the mobile version of my site with button clicks. I used the method wixWindow.scrollTo(X,Y), but this is only for element positions that are fixed, the element positions could change as the elements above them can be collapsed.

---

<div class="post-metadata">

**Author:** ![bilonii](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bilonii/32/15984_2.png) [@bilonii](https://forum.wixstudio.com/u/bilonii)\
**Post date:** [December 26, 2022, 11:09am UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/2 "2022-12-26T11:09:38Z")

</div>

Hi!

Try out:

```javascript
export function button1_click(event) {
  // Get the element with the specified ID
  let element = $w("#anchor1");

  // Scroll the element into view
  element.scrollIntoView();
}

```

---

<div class="post-metadata">

**Author:** ![Cue](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cue](https://forum.wixstudio.com/u/Cue)\
**Post date:** [December 26, 2022, 1:49pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/3 "2022-12-26T13:49:04Z")

</div>

Inorder words $w(‘#anchor1’).scrollIntoView()…?

---

<div class="post-metadata">

**Author:** ![Cue](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cue](https://forum.wixstudio.com/u/Cue)\
**Post date:** [December 26, 2022, 3:31pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/4 "2022-12-26T15:31:03Z")

</div>

This method does not work .

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [December 28, 2022, 7:39pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/5 "2022-12-28T19:39:54Z")

</div>

Hello, I just tested this and it is working as expected for me. I used the following code and on page load with the element collapsed, the page scrolled to the location of that element.

I copied this code exactly from the API docs with no modifications

```javascript
$w("#text4").scrollTo()
  .then( ( ) => {
    console.log("Done with scroll");
} );

```

---

<div class="post-metadata">

**Author:** ![Cue](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cue](https://forum.wixstudio.com/u/Cue)\
**Post date:** [December 28, 2022, 7:59pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/6 "2022-12-28T19:59:00Z")

</div>

The idea is to scroll to the same element (on button click) when the element shifts out of position because of collapsible and expandable elements above it, did it work that way? because as far as I know the scrollTo() method doesn’t do well in this instance.

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [December 28, 2022, 8:06pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/7 "2022-12-28T20:06:52Z")

</div>

All I can recommend is to test it for your use case. If the expand/collapse happens after the scroll - then, yes your position will be lost if this movement causes the page to move.

So perhaps you need to work on some code that awaits the scroll until after all the other actions have happened. wdyt?

---

<div class="post-metadata">

**Author:** ![Cue](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cue](https://forum.wixstudio.com/u/Cue)\
**Post date:** [December 28, 2022, 8:30pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/8 "2022-12-28T20:30:06Z")

</div>

What I want to achieve through a button click is to scroll to a specific element no matter time while viewing the page and no matter the new position of the element. It should just go to that element.

---

<div class="post-metadata">

**Author:** ![amandam](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/amandam/32/79539_2.png) [@amandam](https://forum.wixstudio.com/u/amandam)\
**Post date:** [December 28, 2022, 8:37pm UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/9 "2022-12-28T20:37:44Z")

</div>

Then the code I provided should work (using scrollTo). I’ve not had any issues using it for that purpose before and it is working for me now. I am sorry I am not able to recreate your issue.

---

<div class="post-metadata">

**Author:** ![Cue](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cue](https://forum.wixstudio.com/u/Cue)\
**Post date:** [December 29, 2022, 9:53am UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/10 "2022-12-29T09:53:17Z")

</div>

Just tried it and it works perfectly well.

---

<div class="post-metadata">

**Author:** ![Cue](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Cue](https://forum.wixstudio.com/u/Cue)\
**Post date:** [December 29, 2022, 10:26am UTC](https://forum.wixstudio.com/t/navigating-to-an-anchor-in-mobile/8168/11 "2022-12-29T10:26:22Z")

</div>

Is there also a way to zoom the element with code?
