Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 789525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:32:16+00:00 2026-05-14T21:32:16+00:00

I would like to remove ALL handlers for a given event type. Let’s say

  • 0

I would like to remove ALL handlers for a given event type. Let’s say I’ve added twice “onclick event” to a button and now I would like to return back to the original state where no event handler was set to the button.

How can I do that?

P.S.: I’ve found removeEventListener (non-IE)/detachEvent (IE) methods but the functions want me to pass as a parameter the function that handles the event which seems to me quite clumsy because I would have to store the functions somewhere.

EDIT: http://ejohn.org/blog/flexible-javascript-events/ – I’m now using this code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T21:32:17+00:00Added an answer on May 14, 2026 at 9:32 pm

    http://www.quirksmode.org/js/events_advanced.html – “Which event handlers are registered?” – it seems it’s not possible without DOM 3 level 🙁

    EDIT: I’ve come up with this code. It suits my needs. Maybe it will be helpful for someone else.

    Javascript:

    function DomLib() {
    
    
    }
    
    
    /**
    * Based on: http://ejohn.org/blog/flexible-javascript-events/
    * Function that register event and enables it to be removed without explicitly giving the function definition
    */
    DomLib.prototype.regEventEx = function (el, eventName, funct) {
    
      if (el.attachEvent) {
        el['e'+eventName+funct] = funct;
        el[eventName+funct] = function(){el['e'+eventName+funct](window.event);}
        el.attachEvent( 'on'+eventName, el[eventName+funct] );
      } else {    
        el.addEventListener(eventName, funct, false);
      } 
    
      if(!el.eventHolder) el.eventHolder = [];
      el.eventHolder[el.eventHolder.length] = new Array(eventName, funct);  
    }
    
    DomLib.prototype.removeEvent = function (obj, type, fn) {
      if (obj.detachEvent) {
        obj.detachEvent( 'on'+type, obj[type+fn] );
        obj[type+fn] = null;
      } else {
        obj.removeEventListener( type, fn, false );
      }  
    }
    
    
    DomLib.prototype.hasEventEx = function (el, eventName, funct) {
    
      if (!el.eventHolder) {  
        return false;
      } else {
        for (var i = 0; i < el.eventHolder.length; i++) {
          if (el.eventHolder[i][0] == eventType && String(el.eventHolder[i][1]) == String(funct)) {
            return true;  
          }  
        }
      }
      return false;  
    }
    
    /** 
    * @return - returns true if an event was removed
    */
    DomLib.prototype.removeEventsByTypeEx = function (el, eventType) {
    
      if (el.eventHolder) {  
    
        var removed = 0;
        for (var i = 0; i < el.eventHolder.length; i++) {
          if (el.eventHolder[i][0] == eventType) {                
            this.removeEvent(el, eventType, el.eventHolder[i][1]);
            el.eventHolder.splice(i, 1);
            removed++;
            i--;
          }  
        }
    
        return (removed > 0) ? true : false;
      } else {
        return false; 
      }
    }
    

    Testing HTML page:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Lang" content="en">
    <meta name="author" content="">
    <meta http-equiv="Reply-to" content="@.com">
    <meta name="generator" content="PhpED 5.8">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="creation-date" content="01/01/2009">
    <meta name="revisit-after" content="15 days">
    <title>DomLibTest</title>
    <link rel="stylesheet" type="text/css" href="my.css">
    <!-- FILL IN: Location of your jQuery library -->
    <script type="text/javascript" src="jQuery/jQuery-current.js"></script>
    <!-- FILL IN: Plugin for debugging ... http://www.ecitadel.net/blog/2009/12/08/developing-jquery-use-dump-instead-alert -->
    <script type="text/javascript" src="jQuery/jQuery.dump.js"></script>
    <script type="text/javascript" src="DomLib.js"></script>
    </head>
    <body>
    
      <div id="testElem-1"></div>
      <script type="text/javascript">
      <!--
    
        var domLib = new DomLib();
    
        function removeTest(el) {
    
          var funct = function() { alert("#1: How Are You?");};
          var funct2 = function() { alert("#2: How Are You?");};                  
    
          domLib.regEventEx(el, "click", funct);
          domLib.regEventEx(el, "mousemove", funct2);
          domLib.regEventEx(el, "mousemove", funct2);
          domLib.regEventEx(el, "mousemove", funct2);
    
          $.dump(el.eventHolder);      
          domLib.removeEventsByTypeEx(el, "mousemove");      
          $.dump(el.eventHolder);
        }
    
        removeTest(document.getElementById('testElem-1'));
    
      -->
      </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to remove all elements from XML except content of element called
I would like to build a php website and I would like to remove
While installing an application onto a client's server, I would like to make sure
How I Remove all Div contents but not the div using jquery? the div
I have a simple form (textbox, submit button) which is wrapped in an update
I'd like to download, extract and iterate over a text file in Python without
I have cells that look like this, one per line: Duffy,John: 'Heritage: Civilization and
I have some troubles with memory leaks in JavaScript. I'm using the Leak Memory
I have a list that gets refreshed every 2 seconds via the Handler postDelayed()
I'm hoping this is a simple one. I run a Rails web app where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.