title: Attaching Events To Classes In MooTools?
body: <p>I am fairly new to MooTools and I'm just a little confused about how to use it and would like a few pointers.</p>
  
  <p>For example, in my app, when an object of one of my classes is initialized, it creates a div element. This div is then placed into another div. The user may create multiple instances of the class. I would now like to know how to add events to this object so that it may react after being clicked, double-clicked and so-on. Below is the class I have created:</p>
  
  <pre><code>var new_Div = new Class({
      initialize: function(name)
      {
          this.newDiv = name + "_div";
          this.newDiv = document.createElement('div');
          this.newDiv.id = this.classDiv;
          this.newDiv.style.width = "200px";
          this.newDiv.style.height = "160px";
          this.newDiv.style.border = "thin red dashed";
          document.body.appendChild(this.newDiv);
      }
  });
  </code></pre>
  
  <p>Divs are created and named by the user by taking there input from a textbox for the divs id. The generate div is then inserted into the body using this code which calls the initialize() function and creates a div:  </p>
  
  <pre><code>var divName= document.getElementById("newdiv_Input").value;
  window[divName+ '_var'] = new new_Div(divName);
  </code></pre>
  
  <p>This then allows for the same type of object to be created with different names.</p>
  
  <p>Now the thing I am confused about is how to attach events to the class. For example, how would I create an event that allows each div to be left clicked and have a function run, this issue of attaching events to the class has really confused me. Could anyone help me out?</p>