addEventListener() and removeEventListener();
These methods exist on all DOM nodes and accept three arguments: the event name to handle, the event handler function, and a Boolean value indicating whether to call the event handler during the capture phase (true) or during the bubble phase (false);
to add an event handler for the click event on a button, you can use the following code:
1 var btn = document.getElementById("myBtn"); 2 btn.addEventListener("click", function() { 3 alert(this.id); 4 }, false)