Answers for "open last tab after reload tab pill bootstrap"

0

open last tab after reload tab pill bootstrap

$(document).ready(function() {
  let tabID = localStorage.getItem('activeTab');
  if (tabID) {
  	$("a[href='" + tabID + "']").tab("show");
  }

  $(document.body).on("click", "a[data-toggle='tab']", function(event) {
  		console.log(event.target);
  		localStorage.setItem('activeTab', this.getAttribute("href"));
  	});
  });

  $(window).on("popstate", function() {
  var anchor = localStorage.getItem('activeTab') || $("a[data-toggle='tab']").first().attr("href");
  $("a[href='" + anchor + "']").tab("show");
});
Posted by: Guest on October-06-2021
0

open last tab after reload tab pill bootstrap

This is the best one that I tried:

$(document).ready(function() {
    if (location.hash) {
        $("a[href='" + location.hash + "']").tab("show");
    }
    $(document.body).on("click", "a[data-toggle='tab']", function(event) {
        location.hash = this.getAttribute("href");
    });
});
$(window).on("popstate", function() {
    var anchor = location.hash || $("a[data-toggle='tab']").first().attr("href");
    $("a[href='" + anchor + "']").tab("show");
});
Posted by: Guest on October-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language