Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!