title: JQuery adding object function using .on()
body: <p>I'm trying to add an object's function to a button that is created when some conditions are met. Does it matter if I have the var I'm trying to change outside document.ready?</p>
  
  <pre><code>var myvar = 1;
  $(document).ready(function(){
   var myobj = {
    changeMyVar: function(){ myvar++;}
   }
  ...
  /* button id='my-button' is created in a div id='mydiv' */
  ...
   $('#mydiv').on('click', '#my-button', myobj.changeMyVar);
  });
  </code></pre>
  
  <p>No function is attached to the button and no error is thrown. In fact, console.log(myobj.changeMyVar) returns undefined. What am I missing here?</p>
  
  <p>Edit: I lied about no errors, I get a 'undefined is not a function' on the .on() line.</p>
  
  <p>Thanks!</p>
  
  <p>Edit2: After further analysis, I discovered a silly type-o in my original code. Thanks for the answers!</p>