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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:42:23+00:00 2026-05-23T22:42:23+00:00

How can I store which events were removed with unbind and re-apply them later?

  • 0

How can I store which events were removed with unbind and re-apply them later?

Suppose that I have this element:

<div id="thediv">The Div</div>

Which has a varying number of functions attached to its onclick event. I know I could use unbind to remove all the onclick functions:

$("#thediv").unbind("click");  

How can I store the unbound functions so as to re-bind them later?

Note that this must work with jQuery 1.5.


I did see this previous answer , but there a couple of things I didn’t understand about it:

  • Why is it binding first and then unbinding?
  • What is ary_handlers[idx] doing?

(I’m not really looking for answers to these questions, unless they are necessary to explain the solution for my question about capturing the unbound functions.)

  • 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-23T22:42:24+00:00Added an answer on May 23, 2026 at 10:42 pm

    I think you could do something like this:
    you store the events of the div by cloning the div and saving data(‘events’) in an object. Afterwords you iterate on the object and bind back the events. You have to clone because when you unbind the events the original data(‘events’) are deleted.(hope i understood what you are looking for)

    <div id='my'>my</div>
    
    var my = $('#my');
    my.click(function(){
       alert('my');
    });
    
    my.hover(function(){
    $(this).css('color', 'red');
        });
    
    my.click(function(){
       alert('you');
    });
    
    var ev =my.clone(true).data('events');
    
    my.unbind();
    
    for (var e in ev){
        //you have to iterate on the property since is an array with all the handlers for the same event)
        for (i= 0; i < ev[e].length; i++){
           my.bind(e, ev[e][i]);   
        }
    }
    

    fidlle http://jsfiddle.net/pXAXW/

    EDIT – To make this work in 1.5.2 you just need to change the way you attach back the events because they are saved differently:

      $(document).ready(function(){
    
       var theDiv = $("#thediv");
    
       theDiv.click(function(){
         $(this).css("border-color", "blue");
         alert("Click!");
       });
           theDiv.click(function(){
         $(this).css("border-color", "blue");
         alert("clack!");
       });
    
       var theEvents = theDiv.clone(true).data("events");
    
       //  Unbind events from the target div
       theDiv.unbind("click");
    
       //  Put the saved events back on the target div
       for (var e in theEvents){
         //  must iterate through since it's an array full of event handlers
         for ( i=0; i<theEvents[e].length; i++ ){
           theDiv.bind(e, theEvents[e][i].handler);
         }
       }
    
     });
    

    fiddle here: (the same as Katiek) http://jsfiddle.net/nicolapeluchetti/CruMx/2/ (the event is triggered twice if you don’t click exactly on the div!)
    I also updated my fiddle to use jquery 1.5.2 http://jsfiddle.net/pXAXW/1/)

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

Sidebar

Related Questions

What I can think of is: Algo: Have a hash table which will store
I have a generated nested Array which I store some data. How can i
We have a class which manages many queues that store data. I want a
how we can store the e mail id into a database? i mean which
Where can I store folder's paths, which can be accessed from every function/variable in
I'm designing a database which will store information about some artists. These artists can
Preferences objects present a way to store arbitrary data into Rally which can be
I need store just 10 arrays in my app, which I can change from
I want to store the current date & time which can be get by
I have a plugin which is applied on few element. Is there any way

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.