javascript - How to hide an element only if it matches specific hash? -
i'm trying hide form if it's on root site, or on specific hash https://www.example.com/#uno. code below causing form not show on subpages (/#dos, /#tres, etc). can me understand happening?
$(function(){ if (location.hash == "" || location.hash == "#uno"){ $("#form").hide(); } else { $("#form").show(); }; }());
this because hide form once, don't make reappear until reload page. (you check hash once, when loading entire page, not when hash changes.
function showhideform() { if (location.hash == "" || location.hash == "#uno"){ $("#form").hide(); } else { $("#form").show(); }; } window.onhashchange = showhideform;
Comments
Post a Comment