How do I add an event listener to multiple buttons and get the value of each one depending on the one clicked. Eg:
<button id='but1'>
Button1
</button>
<button id='but2'>
Button2
</button>
<button id='but3'>
Button3
</button>
<button id='but4'>
Button4
</button>
So that on javascript, I wouldn't have to reference each button like:
Const but1 = document.getElementById('but1');
but1.addEventListener('click');
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…