hi i want to add active class to target links in menu. so i have to check target link and add active class to related link in menu bar,
like below
for example if i have “mysite.com/home/public/user/manage” i will split the link and recognize its user page so i have to assign active class to user item in menu bar by jquery.
i did something by below code:
jQuery(document).ready(function($){
// make current item active
var path = window.location.pathname.split("/").pop();
var pathArray = window.location.pathname.split( '/' );
var pathsec=pathArray[3];
// Account for home page with empty path
switch (pathsec) {
case 'operation':
var target = $('ul li#manageoperation');
break;
case 'user':
var target = $('ul li#manageuser');
break;
case 'meta':
var target = $('ul li#mobilehome');
break;
case 'report':
var target = $('ul li#report');
break;
default:
var target = $('ul li#index');
}
// Add active class to target link
target.addClass('active');
});
but if i use my script in another domain or sub-domain i have to edit jquery (change index number of pathArray[3]) code for recognize right part…
how can i find path part without changing this array? using another ways?