- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to work with addEventListener() method in JavaScript HTML DOM?
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>
Advertisements
To Continue Learning Please Login
Login with Google