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

251
Vistas
Show class only on subpages of a parent link?

So what i would like to achieve is to show a class only on subpages of a certain parent page and hide on the rest of the pages. I looked it up and learned i can achieve this with jQuery through page IDs. But this subpages keep getting updated so is there a way to make this automatic?

.sidebar {

example page and subpage;

https://example/event/   
https://example/event/pikachu

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. Get the pathname: const { pathname } = window.location
  2. Check if it's the pathname you want to target
  3. Show the class

e.g.:

https://www.example.com/path1  <-- Hide the class
https://www.example.com/path1/path2  <-- Show the class
https://www.example.com/path1/path3  <-- Show the class
https://www.example.com/path1/path2/path4  <-- Show the class
etc...
// .sidebar class allowed only for sub paths of /path1
// This is the logic //////////////////////////
const { pathname } = window.location;
const target = /^\/path1.*/gim;
if (target.test(pathname) && pathname !== '/path1')
node.classList.add('sidebar');
else node.classList.remove('sidebar');
///////////////////////////////////////////////

You can test a demo HERE

about 4 years ago · Juan Pablo Isaza Denunciar
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