javascript onclick event listener
snippet in javascript

javascript onclick event listener

user8320

document.getElementById("myBtn").addEventListener("click", function() {
  alert("Hello World!");
});

event listener javascript

user5297

const element = document.querySelector(".class__name");

element.addEventListener("click", () => {
	console.log("clicked element");
});

javascript event listener

user2257

let element = document.getElementById("xyz");
//	Event Listener
element.addEventListener("click",  myFunction);

// Call Function On Click
function myFunction() {
  alert("Hello World!");
} 

javascript add an event to a button

user246


 document.getElementById("myBtn").addEventListener("click", function(){
  document.getElementById("demo").innerHTML = "Hello World";
}); 

javascript event listener

user5783

element.addEventListener("click", function(){ 
   element.innerText = "something"; 
}); 

What is addEventListener

user5882


 document.getElementById("myBtn").addEventListener("click", displayDate);