This site is mobile accessible. Press the "Tap Here" button to use a smaller font-size.



Smartphone icons created by Freepik - Flaticon

JS addEventListener()

This example uses the addEventListener() method to attach a click event to a button.

//listen for click on button with id="myBtn"
document.getElementById("myBtn").addEventListener("click", displayDate);

//handle the event
function displayDate() {
  document.getElementById("demo").innerHTML = Date();
}