In an effort to achieve a responsive design, I am seeking to add an active class to an unordered list item based on the specific page that the user is viewing. Essentially, I want to implement conditional formatting using jQuery while learning on MAMP.
Currently, I am following a slow method...
HTML
<nav id="main-site-nav" class="main-menu">
<ul>
<li><a href="index.php" class="crnt-page">Home</a></li>
<li><a href="/services.php">Services</a></li>
<li><a href="/certification.php" >Certification</a></li>
<li><a href="/customers.php">Customers</a></li>
<li><a href="/contact-me.php">Contact Me</a></li>
</ul>
</nav>
CSS
#main-site-nav .crnt-page {
color: #E8A317;
text-decoration:none;
}
I currently have to manually add the class for each list item. My goal is to streamline this process by implementing it in my main.js file at the bottom of the page. Any assistance would be greatly appreciated.
UPDATE!
This PHP solution worked well. However, I am considering migrating it to Wordpress.
<nav id="main-site-nav" class="main-menu">
<ul>
<li><a <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="crnt-page"';?>href="index.php">Home</a></li>
<li><a <?php if (strpos($_SERVER['PHP_SELF'], 'services.php')) echo 'class="crnt-page"';?>href="/services.php">Services</a></li>
<li><a <?php if (strpos($_SERVER['PHP_SELF'], 'certification.php')) echo 'class="crnt-page"';?>href="/certification.php">Certification</a></li>
<li><a <?php if (strpos($_SERVER['PHP_SELF'], 'customers.php')) echo 'class="crnt-page"';?>href="/customers.php">Customers</a></li>
<li><a <?php if (strpos($_SERVER['PHP_SELF'], 'contact-me.php')) echo 'class="crnt-page"';?>href="/contact-me.php">Contact Me</a></li>
</ul>
</nav>
Appreciate the prompt responses! Now I just need to familiarize myself with the pre-formatted code option in Stack Overflow :)