Skip to content Skip to sidebar Skip to footer

Active State On Nav After Page Refresh

This is the code I am using at the moment to add an active state to an item after your clicked on one of the navigation and the page has been redirected. I was wondering if there w

Solution 1:

You can try this: http://jsfiddle.net/jaiprakashsah/thrDq/

var url = document.location.href;
var str = url.substr(0, url.lastIndexOf('/'));
var nUrl = str.substr(str.lastIndexOf('/')+1);

$('ul#ulMenuNav li a:contains('+nUrl+')').addClass('active');

Solution 2:

How about:

$(document).ready(function () {         
  var current_page = document.location.href;

  $('ul#ulMenuNav li a').removeClass('navActive');
  $('ul#ulMenuNav li a[href*="'+current_page+'"]').addClass('navActive');

});

Post a Comment for "Active State On Nav After Page Refresh"