Based on Using Jquery to add / remove a class based on body id :
var bodyID = $('body').attr('id'); $("a[href$='" + bodyID + ".php']").toggleClass('current-selected');
OR
$("a[href$='" + bodyID + ".php']").addClass('current-selected');
Instead of "=" we use the syntax "$ =" (referring to the syntax "href $ ="), which will correspond to the end of the line, so both "index.php" and "/index.php" will correspond to "index.php".
To implement it on your site, you need to run the above code inside the jQuery ready function, so all the HTML code under the script block is loaded before Javascript performs the actions on it:
EDIT: this works for all the main / top navigation links for your site (the href matching string is the last segment of the URL path):
<script type="text/javascript"> $(document).ready(function(){ page = window.location.pathname.substring(1).replace(/\//g,''); $("a[href*='" + page + "']").addClass('current-selected'); }); </script>
source share