I have this script adds an active class to a navbar link based upon the current page. The issue that I am having is it throws off an error when I access a page not in the navigation bar. The error is '$' is undefined. So I am assuming since it can't find the page name in the navbar, it is throwing an error.
I am using a .net master page. I have this script along with the navbar in the master page.
$(document).ready(function() {
var current = location.pathname;
$('.nav li a').each(function(){
var $this = $(this);
if ($this.attr('href').indexOf(current) !== -1) {
$this.addClass('active');
} else {
$(this).removeClass( "active" );
}
})
});