Which button was pressed?

<button id="b1" value="receive">receive</button>
<button id="b2" value="reject">reject</button>

js

 var el = document.getElementsByTagName("button");
 el.addEventListener("click",do,true);

function do(){
}

when b1 is pressed, the do function alert gives the id value of the pressed button. Excuse me, how to write the do function?

Mar.16,2021

el is an array. You cannot add events directly
Loop arrays add events. In the do function, use this.id to get the id value


add a do is the keyword


Search the key words for such a simple question: "js event" and take a good look at it for an hour.


$("button").on("click",function(){

alert($(this).attr("id"))

})

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2c493-4e76b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2c493-4e76b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?