Kevin Powell - CommunityKP-C
Kevin Powell - Community3y ago
144 replies
Matt

Getting Data from Multiple Buttons on Click

Hello,

I'm trying to add an event listener to all buttons within a div, using code such as:

const button= document.querySelectorAll(".percentBtn")

buttons.forEach((btn) => {
    btn.addEventListener('click', calculate);
})


I then need to be able to get the value of each button depending on click. I call the calculate function (not added here) which will eventually do a calculation based on an input & the value attribute of a button. However, I'm not sure how to get the value attribute of the button clicked. I know I can log all values but running btn.value, but I need to be able to do so on click.
Was this page helpful?