Note that there are some explanatory texts on larger screens.

plurals
  1. POEnable/Disable events of DOM elements with JS / jQuery
    primarykey
    data
    text
    <p>I stuck here with a little problem I have put pretty much time in which is pretty bad compared to its functionality. </p> <p>I have tags in my DOM, and I have been binding several events to them with jQuery..</p> <pre><code>var a = $('&lt;a&gt;').click(data, function() { ... }) </code></pre> <p>Sometimes I would like to disable some of these elements, which means I add a CSS-Class 'disabled' to it and I'd like to remove all events, so no events are triggered at all anymore. I have created a class here called "Button" to solve that</p> <pre><code>var button = new Button(a) button.disable() </code></pre> <p>I can remove all events from a jQuery object with $.unbind. But I would also like to have the opposite feature</p> <pre><code>button.enable() </code></pre> <p>which binds all events with all handlers back to the element OR maybe there is a feature in jQuery that actually nows how to do that?!</p> <p>My Button Class looks something similar to this:</p> <pre><code>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 } } </code></pre> <p>Any ideas? Especially this rebind functionality must be available after disable -> enable</p> <pre><code>var a = $('&lt;a&gt;').click(data, function() { ... }) </code></pre> <p>I found these sources that did not work for me: <a href="http://jquery-howto.blogspot.com/2008/12/how-to-disableenable-element-with.html" rel="noreferrer">http://jquery-howto.blogspot.com/2008/12/how-to-disableenable-element-with.html</a></p> <p><a href="http://forum.jquery.com/topic/jquery-temporarily-disabling-events" rel="noreferrer">http://forum.jquery.com/topic/jquery-temporarily-disabling-events</a> -> I am not setting the events within the button class</p> <p>Appreciate your help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload