Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

233
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda