How to work with addEventListener() method in JavaScript HTML DOM?

JavascriptObject Oriented ProgrammingFront End Technology

Use the addEventListener() method to attach an event handler.


You can try to run the following code to learn how to work with addEventListener() method in JavaScript −

<!DOCTYPE html>
      <p>Double click the below button.</p>
      <button id = "btnid"> Double Click </button>
      <p id = "pid"> </p>
         document.getElementById("btnid").addEventListener("dblclick", displayEvent);
         function displayEvent() {
            document.getElementById("pid").innerHTML = Date();
Updated on 23-Jun-2020 12:11:48