I’m making a menu and I would like to add class=”selected” to the active menu items. I have issues with location.pathname when the URL is like:
– http://www.google.com/sub-folder/adrov48.php
So it basicaly works only when url is simple like that:
– http://www.google.com/adrov50.php
I know there is lot of similair questions, but If you take a look at the code below I’m using a “new” method, but it’s not really working, that’s where you guys jump in 🙂
Javascript code:
var path = location.pathname;
$("a[href='" + [path] + "']").parents("li").each(function() {
$(this).addClass("selected");
});
Any ideas how can I make this work, possible with jQuery.
If anyone thinks that my method is bad or not ideal, please tell me why and post or link me your solution.
Thanks in advance!
Why don’t you do something like this: