Highlighting the Menu Item for the Current Page
-
Hi,
I am trying to implement a navigation-menu at the top of my WP-site, and I would like that the menu item for the current page to be highlighted.The nagigation-menu in the header.php, look like this:
<nav class="primary"> <ul id="topnav" class="sf-menu"><li><a href="https://localhost/wordpress/wordpress/?page_id=63">Home</a></li> . . . .
The correspondig CSS, look like this:
#topnav { margin:0; height:63px; } .sf-menu { padding:0px 0px 0px 0px; position:relative; background:none; text-align:left; display:block; } .sf-menu li { position:relative; list-style:none; } .sf-menu a:hover { background-color: #254a0a; !important } .sf-menu li a { font-weight:normal; background:none; text-decoration:none; display:block; } .sf-menu li a selected { background-color: #254a0a; }
And this is the javascript, placed in the header:
<script type="text/javascript"> $(document).ready(function(){ $('.sf-menu a').each(function(index) { if(this.href.trim() == window.location) $(this).addClass("selected"); }); }); </script>
Can anyone see why this is not working?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Highlighting the Menu Item for the Current Page’ is closed to new replies.