I’m having a weird problem.
I have a div that is hidden via css display:none, and each page has an id on the body tag.
now when I load the pages by hitting enter in the address bar, or by a link to that page, everything loads normally, and the div that needs to be shown shows up.
But not if I hit the F5 button to refresh the page.
Super simple jquery, but doesn’t work on F5? Bug? or something Im missing?
html
<body id="projects">
<ul id="sub_navigation" class="projects">
<li>stuff</li>
<li>stuff</li>
</ul>
css
#sub_navigation.projects{display:none;}
Jquery
$(document).ready(function(){
var page = $('body').attr('id');
$('#sub_navigation.'+page).show();
});
You’re finding the element by the ID, so you shouldn’t need the page ID. Try this instead:
I don’t know how many elements use the
projectsclass name, but would it be possible to get the element by the class name?:Or how about this maybe?: