You can do it like this:
document.addEventListener('click', (ev)=>{
console.log(ev.target.id)
});
ev.target
is the element you click on. Thus, you can easily find it's id by using ev.target.id
. There is no need to create a list of all elements ID's at the start.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…