In my web base project with php, I want to apply css class (.active) to current url path, when user click on navigation menu bar, i.e my navigation menu
<li><a href="http://localhost:8000/OhdyDaran')">Designation</a></li> <li><a href="http://localhost:8000/gallery">Gallery</a></li> <li><a href="http://localhost:8000/Introduction">introduction</a></li> <li><a href="http://localhost:8000/home">Home</a></li>
How to apply .active css class with Jquery or JS, after page is refresh, the link is css applied ?
I try the following code but its not working
Try this.
$(document).ready(function () { var link = window.location.href.split('/'); var page = link[link.length - 1]; var url = link[link.length - 2]; // now select the link based on the address $('li > a[href="'url + '/' + page + '"]').closest('li').addClass('active'); });