JSFiddle - React, Tailwind, and code Playground
HTML
<button id="Button1" data-custom="btn1">
Button 1
</button>
<button id="Button2" data-custom="btn2">
Button 2
</button>
<button id="Button3" data-custom="btn3">
Button 3
</button>
JavaScript
function binder(ids, callback) {
ids.forEach(function(id) {
var btn = document.getElementById(id);
btn.addEventListener('click', callback);
});
}
function functionWithButtonContext(event) {
var custom = event.currentTarget.dataset.custom;
console.log('custom:', custom);
}
binder(['Button1', 'Button2', 'Button3'], functionWithButtonContext);