JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<head>
<title>Test JS </title>
</head>
<body>
<div>
Testing ClassName Btn
</div>
<div>
<button class="hello-btn">
Hello BTN 1
</button>
<button class="hello-btn">
Hello BTN 2
</button>
<button class="hello-btn">
Hello BTN 3
</button>
<button class="hello-btn">
Hello BTN 4
</button>
</div>
</body>
</html>
JavaScript
window.onload = function(){
var helloBtn = document.getElementsByClassName('hello-btn');
console.log(helloBtn);
for(var i = 0; i < helloBtn.length; i++ ){
var btn = helloBtn[i];
btn.addEventListener('click', function handleClick(event) {
console.log('btn clicked', event.target.innerText, event);
});
}
}