1

I want to use the same button handler for a vanilla JS script. Is there a way to use something like an event handler to get the ID of the button which was pressed, and pass that into the subroutine?

Pseudocode to get the point across

document.addEventListener('buttonClick', (event) => {
    drawComponent(event.clientX, event.clientY, event.buttonID);
})

I'm using ASP.Net MVC, electron, and the Razor View Engine if that's relavent.

Marf Bot
  • 55
  • 1
  • 7

1 Answers1

1

Use event.target

document.addEventListener('buttonClick', (event) => {
    console.log("element: " + event.target);
    drawComponent(event.clientX, event.clientY, event.buttonID);
})
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80