addEventListener
How it works
// Syntax
// element.addEventListener(event, function, useCapture)
// event Required. A String that specifies the name of the event
// function Required. Specifies the function to run when the event occurs
// useCapture Optional. A Boolean value that specifies whether the event should be executed in the capturing or in the bubbling phase.
// script
// document.getElementById("tmBtn").addEventListener("click", function(){
this.style.backgroundColor = "red";});
Back
Home