crystaltrumpet,
может так сработает
$(window).on("load", function() {
var a = $(".tabflex .tab");
a.click(function() {
a.css("background", "rgba (128,128,128, 0.5)");
$(this).css("background", "gray")
});
function out() {
var elem = $(":target"),
str = "все блоки закрыты";
if (elem.length) str = "блок " + elem[0].id + " открыт";
$("#state").text(str)
}
$(window).on("hashchange", out).trigger("hashchange");
});