Vanilla JS sur le clic
var div = document.getElementById('myId');
div.addEventListener('click', function(e){
console.log(this.getAttribute('id'))
});
Friendly Fly
var div = document.getElementById('myId');
div.addEventListener('click', function(e){
console.log(this.getAttribute('id'))
});
let newButton = document.createElement('button');
newButton.setAttribute("id", "myNewButton");
newButton.className = "myClassName";
newButton.innerText = "clickMe";
newButton.addEventListener("click", clickMe);
document.body.appendChild(newButton);
function clickMe(){
console.log("Hi! I am a new Button.");
}