title: Call class instance method onclick javascript
body: <p>I have a javascript file with classes which contain method functions. I was wondering how to go about calling a class instance method from an onClick event.</p>
  
  <pre><code>function MyClass()
  {
      this.instanceData = "Display Me";
  
      this.DisplayData = function()
      {
          document.write(this.instanceData);
      }
  }
  
  var classInstance = new MyClass();
  </code></pre>
  
  <p>How would I call the DisplayData function on classInstance from an onClick event. For example:</p>
  
  <pre><code>&lt;button onClick="classInstance.DisplayData()"&gt;Click Me!&lt;/button&gt;
  </code></pre>
  
  <p>Which doesn't work, but helps me clarify what I'm looking to do. Any suggestions?</p>