I am stuck here with a small problem that I spent quite a bit of time in which is pretty poor compared to its functionality.
I have tags in the DOM, and I have associated several events with them using jQuery.
var a = $('<a>').click(data, function() { ... })
Sometimes I would like to disable some of these elements, which means that I add the 'disabled' CSS class to it, and I would like to delete all events, so no events will be fired anymore. I created a class called "Button" to solve this
var button = new Button(a) button.disable()
I can remove all events from jQuery object using $ .unbind. But I would also like to have the opposite function
button.enable()
which binds all events to all handlers back to the element OR maybe there is a function in jQuery that actually knows how to do this ?!
The My Button class looks something like this:
Button = function(obj) { this.element = obj this.events = null this.enable = function() { this.element.removeClass('disabled') obj.data('events', this.events) return this } this.disable = function() { this.element.addClass('disabled') this.events = obj.data('events') return this } }
Any ideas? Especially this repeat function should be available after disconnecting β enable
var a = $('<a>').click(data, function() { ... })
I found these sources that did not work for me: http://jquery-howto.blogspot.com/2008/12/how-to-disableenable-element-with.html
http://forum.jquery.com/topic/jquery-temporarily-disabling-events -> I do not set events in the button class
Appreciate your help.