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

276
Visualizações
Show/Hide HTML by URL using JS if-else statement

I need to build out a JS if-else function with the objective of:

if my web page is a “county", I want to display an HTML list showing “cities” nested within the county. I have 93 counties each with their own list of cities. I must show cities specific only to the parent county.

else I want to show the list of 93 cities.

So, I'm curious how to tell JS that if URL ends with this slug, do this thing; else do the default thing.


This website has exactly what I'm looking to build - see the location icon in the top left. The first list is a county, and when clicking a county, the list then changes to another list of cities.

The data for the list looks like this and I imagine any of these data points can be used to trigger the JS but my guess is to use the URL slug. Then, in HTML, have all 93 lists separated with classes.


Or, is there an easier way to do this? would greatly appreciate some help.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use window.location to work with url i think what you're looking for is

window.location.pathname

about 4 years ago · Santiago Trujillo 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