Is there a way to retrieve the value of a button when multiple buttons are generated dynamically? I have a JavaScript function that creates buttons in a list based on my search history, with each button labeled as a city name.
However, after clicking on one of these created buttons, the value returned is undefined.
function recentSearch(city) {
var newButton = document.createElement("button");
newButton.setAttribute("value", city);
newButton.textContent = city;
document.getElementById("searchHistory").append(newButton);
cities.push(city);
localStorage.setItem("searches",JSON.stringify(cities));
}