jQuery - How to Add Active Class to Current link matching Page URL?
Method 1 - On Page Load
If you want to add a class (active) to current link matching page URL on page load. Here is the working codejQuery('.ma-menu-list li a[href="' + window.location.href + '"]').addClass('active');
Method 2 - On Link Click
If you want to add a class (active) to current link while clicking on the link. Here is the working codejQuery('.ma-menu-list li a').on('click', function(){
jQuery('.ma-menu-list li a').removeClass("active");
jQuery(this).addClass("active");
});
No comments:
Post a Comment