Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda