# Scroll to element issues

**URL:** <https://community.weweb.io/t/scroll-to-element-issues/5297>\
**Category:** Ask us anything\
**Tags:** design\
**Created:** [November 8, 2023, 3:58pm UTC](https://community.weweb.io/t/scroll-to-element-issues/5297 "2023-11-08T15:58:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/adam/32/9449_2.png) [@Adam](https://community.weweb.io/u/Adam)\
**Post date:** [November 8, 2023, 3:58pm UTC](https://community.weweb.io/t/scroll-to-element-issues/5297/1 "2023-11-08T15:58:52Z")

</div>

Hi,  
I have a page in my website that contains a table of contents with hyperlinks that scroll to corresponding paragraphs on that page.

I gave the paradraphs html ids that are used by the table of contents “on click” to scroll the page to the relevant paragraph. The following is the custom js:

```auto
const elementID = context.item.data?.['id'];

const node = document.getElementById(elementID);

const yourHeight = 88; //This is how far down the page you need the element to scroll to. Relevant primarily if you have a sticky horizontal navigation/header.

node.scrollIntoView(true);

const scrolledY = window.scrollY;

if (scrolledY) {
  window.scroll(0, scrolledY - yourHeight);
}

```

I’m experiencing 2 issues:

1. The js logic works for the editor, but is off in the published website.  
Here is the table of contents:  

2. The other issues is when i’m in the published website and I click a link from the table of contents, it scrolls down the page near the clicked element (but not exactly, as specifies above). Then if I try to click a link from the visible part of the table of contents in the current position, the screen moves a bit, but doesnt go near the requested paragraph. This behaviour only fails in the published version, not the editor.  
[Video](https://drive.google.com/file/d/1wtmoR88_f7WuG6WQVTEtHcYeZKXFG4Qc/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![Mael](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/mael/32/13246_2.png) [@Mael](https://community.weweb.io/u/Mael)\
**Post date:** [November 9, 2023, 5:17pm UTC](https://community.weweb.io/t/scroll-to-element-issues/5297/2 "2023-11-09T17:17:11Z")

</div>

Hello @Adam,

It should work like you did. I replicated what you did in a personal project and it’s working

Could you create a ticket on this app: [https://support.weweb.io/](https://support.weweb.io/)

Please send the link of your editor and credential if needed to see the data and test. We will take a look
