How do find the id of the button which is being clicked?
You need to send the ID as the function parameters. Do it like this:
B1 B2 B3
This will send the ID this.id as clicked_id which you can use in your function. See it in action here.
this.id
clicked_id