JSFiddle - React, Tailwind, and code Playground

by bvotcode

HTML

<body>
    <button id="b1" class="button">
        button1
    </button>
    <button id="b2" class="button">
        button2
    </button>
</body>

JavaScript

const button1 = document.getElementById('b1')
    const button2 = document.getElementById('b2')

    const myCustomListener = function(e) {
        console.log(e.target.id) // b1 or b2
    }

    button1.addEventListener('click', myCustomListener )
    button2.addEventListener('click', myCustomListener )