Tabs that follow the URL hash

The address bar shows the open tab, so a link can open a specific tab and Back works.

jQuery · Tabs that follow the URL hashAdvanced
function openTab(hash, push) {
  const $pane = $(hash);
  if (!$pane.length || !$pane.hasClass('tab-pane')) hash = $('.tab-link:first').attr('href');
  $('.tab-pane').hide().filter(hash).show();
  $('.tab-link').removeClass('on').attr('aria-selected', 'false')
    .filter('[href="' + hash + '"]').addClass('on').attr('aria-selected', 'true');
  if (push && location.hash !== hash) history.pushState(null, '', hash);
}

$('.tab-link').on('click', function (e) { e.preventDefault(); openTab($(this).attr('href'), true); });
$(window).on('popstate', function () { openTab(location.hash, false); });
openTab(location.hash, false);
tabshashhistorydeep link