It looks like that code is part of a bootstrap4 page and I would guess that this is the basic setup.
That might help you make a solution geared to this setup.
The tabs and panes themselves are controlled automatically by the bootstrap functions I just added a css scroll and activated the tabs from the top menu. I did not check for a url hash but there is a tutorial here.
Bear in mind my JS is very basic
The examples by @rpg_digital and @Archibald are much better if bootstrap can be avoided.