title: Can I unbind events in a jquery plugin namespace, not simply an event namespace?
body: <p>I want to wrap all my jQuery code in a function called init(). This function is defined and then immediately executed. Then, I also use init() on window resize.</p>
  
  <pre><code>$(document).ready(function(){
    function init(){
      ...
  
      $('.button').click(function(){
        $(this).toggleClass('.active');
      });
  
      ...
    };
  
    init();
  
    $(window).resize(function(){
      init();
    });
  
  });
  </code></pre>
  
  <p>The trouble is that a new event listener is created every time the window resizes. That becomes problematic when you are trying to toggle something on click. If there are an even number of listeners, the toggle happens twice, nullifying the whole ordeal.</p>
  
  <p>My next step was to try to unbind all events at the beginning of my init() function:</p>
  
  <pre><code>$('*').unbind();
  </code></pre>
  
  <p>This successfully reset all event binding and ensured only one listener was left after resizing the window. BUT, it killed any other jQuery code used in other plugins and files.</p>
  
  <p>I believe the solution to unbinding the events of my script only, can be achieved via namespaces. However, I don't want to have to force people to have to remember to use .on(), and 'click.namespace', especially if they like using .click(function(){...}); So event namespaces aren't really wanted.</p>
  
  <p>What I really want is a way to disable all events based on a plugin level namespace. Any ideas? At the least, is there a way to extend the click function to operate normally but to place all selectors it is applied to into an array that I can then reference later?</p>
  
  <p>Thanks!</p>