![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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 removeEventListener() method in JavaScript?
Use the removeEventListener() method in JavaScript to remove event handler attached with addEventListener() method.
Example
<!DOCTYPE html> <html> <head> <style> #box { background-color: gray; border: 2px dashed; } </style> </head> <body> <div id="box">Demo Text! <p>Click below to remove event handler.</p> <button onclick="removeEvent()" id = "btnid">Remove</button> </div> <p id="pid"></p> <script> document.getElementById("box").addEventListener("mousemove", display); function display() { document.getElementById("pid").innerHTML = Math.random(); } function removeEvent() { document.getElementById("box").removeEventListener("mousemove", display); } </script> </body> </html>
Advertisements