mvc
Add active class to target link in jQuery
A
Desh-Duniya Team
Author
$(document).ready(function ($) {
// Get current path and find target link
var path = window.location.pathname.split("/").pop();
// Account for home page with empty path
if (path == '')
{
path = 'Home';
}
//var target = $('nav a[href="' + path + '"]');
// Add active class to target link
console.log(location.pathname);
$('nav a[href^="' + location.pathname + '"]').addClass('active');
//$('div ul li a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active');
// target.addClass('active');
});