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

271
Vistas
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 Respuestas
Responde la pregunta

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 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