Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

how to add dynamic Active class on selected page

how to add dynamic Active class on selected page

Problem

http://hotelshimlahill.com/demo/ this website I've made in bootstrap, the header section including nav bar is coming from a separate file called 'header.php' Now i want to add Active Class for each page on which user is visiting. how can i do that? Kindly assist me. Thankyou.

Problem courtesy of: Zaib Azhar Rao

Solution

In your individual page such as about.php, services.php, you can do:

$currentPage = 'about'; // current page is about, do the same for other page
include('header.php');

Then in your header.php, you can check:

Or you can try to use jQuery as well:

$(document).ready(function($){
    var url = window.location.href;
    $('.nav li a[href="'+url+'"]').addClass('active');
});
Solution courtesy of: Felix

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

how to add dynamic Active class on selected page

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×