JSFiddle - React, Tailwind, and code Playground

by makloon

HTML

<a  id="top">TOP</a>
<br /><br /><br /><br />
<a href="#top" class="sectionlinks">Go to top</a>
<a href="#top" class="sectionlinks">Go to top</a>
<a href="#top" class="sectionlinks">Go to top</a>
<a href="#top" class="sectionlinks">Go to top</a>
<a href="#top" class="sectionlinks">Go to top</a>
<br /><br />
<a onclick="goBack()">My Back Link</a>

JavaScript

var count = 0;
var historyValue = -1;
    $(".sectionlinks").click(function () {
        ++count;
        historyValue = "-" + (count + 1);
        console.log(historyValue);
        console.log(count);
    });
    function goBack() {
    window.history.go(historyValue);
  }