Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
active class not working on index page when index doesn't have in url

myapp
├── index.php
├── apps.php
├── contact.php
└── sidebar.php

in sidebar.php

<nav class="side-bar">
        <ul>
            <li>
                <a href="index.php" class="category" >
                    <i class="fi fi-bs-home"></i>
                    <span>Home</span>
                </a>
            </li>
            <li>
                <a href="room.php" class="category">
                    <i class="fi fi-bs-apps"></i>
                    <span>Room</span>
                </a>
            </li>
            <li>
                <a href="contact.php" class="category">
                    <i class="fi fi-br-comment-alt"></i>
                    <span>Contact</span>
                </a>
            </li>
            </ul>
</nav>

in index.php apps.php contact.php

#more code here
 <php include('sidebar.php');
 #more code here

and I use some of JavaScript to add active class on the link of my current page

Note I use active class to highlight on the link of my current page

const category = document.querySelectorAll('.category');
const activePage =windows.location.href;
category.forEach(link =>{
    if(link.href === activePage){
        link.classList.add('active');
    }
})

Problem

Active class work normally when I link to any page like ..\myapp\index.php , But when i open ..\myapp\ It will auto open index.php that make my link tag index.php page doesn't have active class

What I want?

I want to make it active class on home Page (index.php) when I open ../myapp/ in the url

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!