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 7218999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:33:51+00:00 2026-05-28T21:33:51+00:00

I have written the following function which adds an event listener and registers the

  • 0

I have written the following function which adds an event listener and registers the event. Assume that this.$target holds the element id of the target element (for example: if we add event listener on div having id = 'myDiv', then this.$target will be myDiv) and this.$_ points to the target element (for example: this.$_=document.getElementById('myDiv'))

The event is registered in the following way…
There is an array for each type of event listeners for an element. For ex: myDiv_click will hold all click event listeners on div having id = myDiv...Slly myDiv_mouseover will hold all mouse over event handlers of the element..Corresponding to each event ,an event id is returned by the function. Which is in the form eventType_indexInTheArray.. For example: the first mouse click event on an element will have an event id click_0

This works fine…

Now I wrote a function for removing an eventlistener. The function takes the eventId returned by $hear() as argument… But after executing it the event is not deleted.. The function is given below.. What is the bug in it?

   main.prototype.$hear = function(ev,callbackF,order)
    {
            
            if(typeof order == 'undefined' || order =='' )
            order = 0;
            
            
            order = (order == 1)?true:false;
            var a;
            
            if(!(a = (this[this.$target+ev])))//event registration
            a = ((this[this.$target+ev]) = new Array());
            
            a.push(callbackF+"_"+order);
            this.$_.addEventListener(ev,callbackF,order);
            return ev+"_"+(a.length - 1);//event Id
    }


    main.prototype.$miss = function(evId)
      {
            var ev = evId.split("_");
            var evIndex = ev[1];
            ev = ev[0];
            evId = ev;
            if((!(ev = (this[this.$target+ev]))) || ev.length-1<evIndex||evIndex<0)
            {
                
                alert("ERROR \n\n\n Event having event id   "+evId+" is not registered\n");
                return false;
            }
            else
            {
                var temp = evIndex;
                evIndex = ev[evIndex].split("_") ;
                
                this.$_.removeEventListener(evId,evIndex[0],evIndex[1]);
                ev.splice(temp,1);
            }               
    }
  • 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-28T21:33:51+00:00Added an answer on May 28, 2026 at 9:33 pm

    You need to pass exactly the same arguments to removeEventListener like to EventListener. Thus adequate callbackF and order.

    You are not doing so.

    You probably meant

    evIndex = a[evIndex].split("_");
    

    instead of

    evIndex = ev[evIndex].split("_");
    

    and wanted a to be global.

    But still the issue will be that you want get your original Function back from String.

    You need to rethink and redesign your code.

    Simply push:

    { 
       'event_name' : ev,
       'callback' : callbackF,
       'order' : order
    }
    

    into a instead of your concatenated string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written following function which checks whether start_date field is not empty and
i have the following function written in javascript which operate a slide up/down box.
I have written the following function which finds all divisors of a given natural
i have written following function in JS which is called on click of some
I have written a checkers game model which has a Board object that holds
I have written the following function but it's isn't returning anything when I run
I have written the following algorithm in order to evaluate a function in MatLab
I have a container element which can be expanded upon being clicked. This container
Friends, I have written the following JavaScript to ascertain which row of an tabular
I've written the following function which imports .txt files into MATLAB . The .txt

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.