title: Run javascript on text change
body: <p>What I am looking for is slightly subjective, but I am sure there is a better way to do this.</p>
  
  <p>I am looking for a better way to perform javascript while a user is typing content into either a textarea or input box on a website. For instance, sites such as Google Docs are capable of saving changes to documents almost instantly without noticeable performance degradation. Many sites however use a bit of jQuery that might look like the following:</p>
  
  <pre><code>$("#element").on("keyup", function() { /* Do something */ });
  </code></pre>
  
  <p>This works fine for simple things like autocomplete in search boxes, but performance becomes a nightmare once you have any sizable corpus for it to have to deal with (or if a user types fast, yikes). </p>
  
  <p>In trying to find a better way to analyze/save/what-have-you text as the user is typing, I started to do something like this:</p>
  
  <pre><code>var changed = false;
  $("#element").on("keyup", function() { changed = true });
  setInterval(function() { if(changed) { /* Do something */ changed = false; } }, 1000);
  </code></pre>
  
  <p>It seems to alleviate laggy or delayed text input, but to me it seems like a less than elegant solution. </p>
  
  <p>So back to my question, is there a better way to have javascript execute when a corpus has been changed? Is there a solution outside of using intervals?</p>
  
  <p>Thanks.</p>