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

JavascriptObject Oriented ProgrammingFront End Technology

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

Example

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

<!DOCTYPE html>
<html>
   <body>
      <p>Double click the below button.</p>
      <button id = "btnid"> Double Click </button>
      <p id = "pid"> </p>
      <script>
         document.getElementById("btnid").addEventListener("dblclick", displayEvent);
         function displayEvent() {
            document.getElementById("pid").innerHTML = Date();
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 11:33:02
Advertisements