### Bug description

I'm using Quarto for my GitHub page. Command lines for rendering & publishing (`quarto render` and `quarto publish gh-pages`)
My Quarto version is 1.3.302 on MacOS Ventura 13.2.1

On the rendered and published website, when first clicking on a section on the table of contents (TOC), the page seems to scroll a little bit but does not scroll to the chosen section. It only scrolls to the correct place after the second click (on the same section). I tested this on Chrome, Edge, and Safari and have this problem on all of them.

On Chrome and Edge, if at first I go to the website link with tail specifying a section, for example `#code-cell` (section Code Cell), then I will be landed at the right section of the page. However, if after that I change the website link to navigate to another section, say to `#equation` (section Equation), then the page does not move anywhere at all. This remains even after I refresh the website multiple times. However, I do not encounter this issue with Safari.

Below is the HTML output for the TOC.

```HTML
<!-- content -->
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<!-- margin-sidebar -->
    <div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
        <nav id="TOC" role="doc-toc" class="toc-active">
    <h2 id="toc-title">On this page</h2>
   
  <ul>
  <li><a href="#markdown" id="toc-markdown" class="nav-link active" data-scroll-target="#markdown">Markdown</a></li>
  <li><a href="#code-cell" id="toc-code-cell" class="nav-link" data-scroll-target="#code-cell">Code Cell</a></li>
  <li><a href="#equation" id="toc-equation" class="nav-link" data-scroll-target="#equation">Equation</a></li>
  </ul>
</nav>
    </div>
```

Output of `quarto check`

> [✓] Checking versions of quarto binary dependencies...
>       Pandoc version 3.1.1: OK
>       Dart Sass version 1.55.0: OK
> [✓] Checking versions of quarto dependencies......OK
> [✓] Checking Quarto installation......OK
>       Version: 1.3.302
>       Path: /Users/nguyenmts/Applications/quarto/bin
> 
> [✓] Checking basic markdown render....OK
> 
> [✓] Checking Python 3 installation....OK
>       Version: 3.10.9 (Conda)
>       Path: /Users/nguyenmts/anaconda3/bin/python
>       Jupyter: 5.2.0
>       Kernels: python3
> 
> [✓] Checking Jupyter engine render....OK
> 
> [✓] Checking R installation...........(None)
> 
>       Unable to locate an installed version of R.
>       Install R from https://cloud.r-project.org/




### Checklist

- [ ] Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
- [X] Please [format your issue](https://quarto.org/bug-reports.html#formatting-make-githubs-markdown-work-for-us) so it is easier for us to read the bug report.
- [ ] Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
- [X] Please document the operating system you're running. If on Linux, please provide the specific distribution.
- [X] Please provide the output of `quarto check` so we know which version of quarto and its dependencies you're running.
dragonstyle
2023-04-02T10:59:15Z
singuyenmai
bug triaged-to
v1.3
closed
Website does not scroll to section after first click on the TOC
https://github.com/quarto-dev/quarto-cli/issues/5067