JSFiddle - React, Tailwind, and code Playground

by Jeremy Banks

HTML

Jump: <select></select>

<br><br><br>

<h2 id="hello-world">Hello World</h2>

<br><br><br>

<h3 id="hello-bob">Hello Bob</h3>
    
<br><br><br>
    
<h3 id="hello-sam">Hello Sam</h3>
    
<br><br><br>

<h2 id="goodbye">Goodbye World</h2>

JavaScript

var selector = document.querySelector('select');

var titles = document.querySelectorAll('h2, h3, h4');
for (var i = 0; i < titles.length; i++) {
    var titleOption = document.createElement('option');
    titleOption.textContent = titles[i].textContent;
    titleOption.value = titles[i].id;

    selector.appendChild(titleOption);
}

selector.addEventListener('change', function() {
    document.location.hash = selector.value;
});