I’m a beginner web developer who is in the process of putting together a simple website that will use an API to display data from various cities based on different buttons a user can click. I’ve written a general function that takes in a city parameter, runs it through the api and sends the appropriate data back to my HTML page. I’m just having trouble getting the event listener for my buttons to work as expected.
Listener examples:
city1button.onclick = cityInfo("city1");
city2button.onclick = cityInfo("city2");
Based on some research, I now realize that my code is invoking my functions before a button can be pressed. I’ve found some more elaborate solutions online, but was wondering if there is a simple way that could ideally be kept in one line. Thanks in advance. I really appreciate the help.