title: Adding class onclick and then selecting by that class on next click
body: <p>I'm just doing test scenarios trying to understand jquery a little more. I understand that what I'm trying to do won't work and I'm sure I could look up a more complicated solution involving toggle or something but I'd like to know the logic behind why this wont work... </p>
  
  <p>I would like to have a button that when pressed inserts text. When it is pressed again it inserts a different set of text. I'm trying to play with the whole adding/removing classes thing so I'm trying to add class 'text1' to my textarea div. I then go on and create another click function that tries to select that 'text1' class that I just added and insert HTML again. </p>
  
  <p>If I have the 'textarea.text1' selector below my 'textarea' (as shown in my example) selector it understandably goes through and adds the text1 class and then finds it and immediately enters the "Text Content 2" </p>
  
  <p>I thought by having the 'textarea.text1' selector above it would move past the first .click without doing anything and then add the class. This doesn't seem to work... </p>
  
  <p>I then expected to click on the ChangeText button again and have it find the class in the first part of my script.....</p>
  
  <p>Can anyone explain why this isn't working and the simplest method to accomplish this?</p>
  
  <p>Thanks in advance. </p>
  
  <p>Javascript:</p>
  
  <pre><code>$(document).ready(function() {
      $('.changetext').click(function() {
          $('.textarea').html('&lt;p&gt; Text Content 1&lt;/p&gt;').addClass('text1');
      });
      $('.changetext').click(function() {
          $('.textarea.text1').html('&lt;p&gt; Text Content 2&lt;/p&gt;');
      });
  });
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;body&gt;
      &lt;div class="textarea"&gt;&lt;/div&gt;
      &lt;button class="changetext"&gt;ChangeText&lt;/button&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Jfiddle: <a href="http://jsfiddle.net/nlaffey/qzKJx/1/" rel="nofollow">http://jsfiddle.net/nlaffey/qzKJx/1/</a></p>