Have got data from an api call and have looped through it to create elements on the page. What I can't figure out how to do is generate an event listener for each button that is created. I'm not sure I'm using the right id to get each button. Apologies I'm very new to coding.
$('.btn btn-primary').on('click', () => {
// some function
});
cities.forEach((city) => {
$("#citiesContainer").append(`
<div class="citiesRow" class="row">
<div class="col-8"><h5>${city.name}</h5></div>
<div class="col-4">
<button value=${city.id} type="button" class="btn btn-primary">Primary</button>
</div>
</div>
`);
});