Anson Aştepta
Anson Aştepta

Reputation: 1143

Execute if statement everytime when the url hash changed

I am using easytab to create my tab page, therefore page won't refresh when switching tab but I'd need to create an function which will hidden some buttons for specific tab.

So for the javascript, i have built a checker for the url hash

//hiding 30d/90d/1y button for feed 

var FeedPanelchecker = location.hash;
        if(FeedPanelchecker == "#panel-Feeds"){
            $("#30Days").css("display","none");
            $("#12Weeks").css("display","none");
            $("#12Months").css("display","none");
        }
});

But I don't know how to make it excute everytime when the hash tag change, should id use .change()? but it seem for input type elements only

Upvotes: 0

Views: 55

Answers (2)

madalinivascu
madalinivascu

Reputation: 32354

You can trigger the code on easytab after event

    $('#tab-full-container').bind('easytabs:after', function() {
    var FeedPanelchecker = location.hash;
            if(FeedPanelchecker == "#panel-Feeds"){
                $("#30Days").css("display","none");
                $("#12Weeks").css("display","none");
                $("#12Months").css("display","none");
            }
    });

})

Upvotes: 1

Rayon
Rayon

Reputation: 36609

Use onhashchange Event, fires when a window's hash changes

window.addEventListener("hashchange", function() {
  var FeedPanelchecker = location.hash;
  if (FeedPanelchecker == "#panel-Feeds") {
    $("#30Days").css("display", "none");
    $("#12Weeks").css("display", "none");
    $("#12Months").css("display", "none");
  };
});

Upvotes: 2

Related Questions