Posted By

ascarion on 03/08/10


Tagged


Versions (?)

Remove and restore event handlers


 / Published in: jQuery
 

  1. function remove() {
  2. $('.elements').each(function() {
  3. if ($(this).data('events')) {
  4. $(this)
  5. .data('eventStore', eval($(this).data('events').toSource()))
  6. .unbind();
  7. }
  8. });
  9. }
  10.  
  11. function restore() {
  12. $('.elements').each(function() {
  13. var events = $(this).data('eventStore');
  14. if (events) {
  15. for (var type in events) {
  16. for (var num in events[type]) {
  17. $(this).bind(type, events[type][num].handler);
  18. }
  19. }
  20. }
  21. });
  22. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: logicbox on October 14, 2010

The restore function would need a $(this).removeData('eventStore'); to prevent events being restored more than once.

You need to login to post a comment.