I need to build out a JS if-else function with the objective of:
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.
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.