Active links color on language select

Hello i have this code to show a color for the active page/link and this works for these links: mydomain.mysubdomain/test page/ and/or mydomain.mysubdomain/test page/index.php. But i also want this code to work for these links: mydomain.mysubdomain/test page/index.php?lang=en and mydomain.mysubdomain/test page/index.php?lang=se

Thank you.

`jQuery(document).ready(function($){    var url = window.location.href;    
$('.nav a').filter(function() {    return this.href == url;})
.closest('li').addClass('current_yes');

$('.nav-submenu a').filter(function() {    return this.href == url;})
.closest('li').addClass('sub_current_yes').parents('li').addClass('current_yes');});`

Hi,

You probably want to compare window.location.pathname with the links pathname which don’t include the querystring or domain.

return this.pathname == window.location.pathname

Hello, thank you for reply. I can’t realy get this to work. Can you take my code and fill in what you mean?
my real path is this: http://test3.fcab.se/test%20sida/index.php?lang=se and http://test3.fcab.se/test%20sida/index.php?lang=en

Thank you.

jQuery(document).ready(function($){
  var url = window.location.pathname;
  $('.nav a').filter(function() {
    return this.pathname == url;
  })
  .closest('li')
  .addClass('current_yes');

  $('.nav-submenu a').filter(function() {
    return this.pathname == url;
  })
  .closest('li')
  .addClass('sub_current_yes')
  .parents('li')
  .addClass('current_yes');
});

Thank you this is working better, but now even links that hav no link “#” is showing the active color. Also this do not work if i only use http://test3.fcab.se/test sida/ in this case only the “#” link have the active color.

Any ideas please.

Thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.