<button id="button-1">Button 1</button>
<button id="button-2">Button 2</button>
<script>
// Get the buttons
var button1 = document.getElementById('button-1');
var button2 = document.getElementById('button-2');
// Attach click event listeners to the buttons
button1.addEventListener('click', logButtonText);
button2.addEventListener('click', logButtonText);
function logButtonText(event) {
// Get the text of the button that was clicked
var buttonText = event.target.innerText;
console.log(buttonText);
}
</script>
Comments
Post a Comment