For a web app that has multiple buttons on a web page, we can define a single onclick handler by using the call-back function’s this keyword.
When a function is used as an event handler, its this keyword is set to the element that fired the event. (Some browsers do not follow this convention for listeners added dynamically with methods other than addEventListener.)
Examples
Download these examples from Github
- Which Button Was Clicked Demo (JavaScript)
- Which Button Was Clicked Demo (jQuery)