When I use an id for a button, which sends one to the top of the page, then this script works to execute it:
const btnReturnToTop = document.getElementById("returnToTop");
function returnToTop(){
window.location=("#Top");
}
btnReturnToTop.addEventListener('click', returnToTop);
But if I scatter several of these buttons down a long page, I need to use a class, not an id. Then I’m stuck. Using getElementsByClassName in place of getElementById won’t work because the former returns an array, not a specific button pressed.
What scripting do you use to deal with multiple buttons that need to run the same script? I could make every button a different id and duplicate the function to deal with each id, but I’m sure JavaScript has a more elegant way.
I’m not getting any errors in the console, yet the buttons don’t take me anywhere. Maybe because they are “input” buttons, there should be a difference there.