title: jQuery keypress event for many dynamically added textareas
body: <p>I want to write a little chat. 
  On the first load of the page old messages and answers will be loaded from the database. So I have many messages with different IDs. For every message I have a link to reply. When you click on it a message box appears. My problem is, that I want to send the reply when the user press Enter on his keyboard.</p>
  
  <p>The reply textareas are added with jquery so I can't use $(textarea).keypress(.....)</p>
  
  <p>Here is a example of my code:</p>
  
  <pre><code> &lt;div id="container" style=""&gt;
  &lt;div id="main" role="main"&gt;
      &lt;div id="shoutbox_container"&gt;
          &lt;div id="shoutbox_content" style="margin-top:20px;"&gt;&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>for (id = 0; id &lt; 5; id++) {
     var res_container = '&lt;div id="shoutbox_entry_' + id + '" class="entry entrybox"&gt;';
     res_container += 'Mr Idontknow wrote:' + id + '. Message ';
     res_container += ' &lt;span class="reply" id="reply" data-parentid="' + id + '"&gt;reply&lt;/span&gt; ';
     res_container += '&lt;div class="replytextbox replybox" id="reply_textbox_' + id + '" style="display:none;"&gt;';
     res_container += '&lt;textarea class="replytext" name="antwort" id="antwort_' + id + '" data-parentid="' + id + '"&gt;&lt;/textarea&gt;';
     res_container += '&lt;button id="replysend"&gt;send&lt;/button&gt; ';
     res_container += '&lt;/div&gt;';
     res_container += '&lt;/div&gt;&lt;br&gt;&lt;br&gt;';
     $('#shoutbox_content').prepend(res_container);   } 
  
  //reply textarea   
  $('#shoutbox_content').on('click', '#reply', function () {
     var parentid = $(this).data('parentid');
     $('#shoutbox_content').find('#reply_textbox_' + parentid).toggle();
  });
  
  //reply send button
  $('#shoutbox_content').on('click', 'button', function () {
     var parentid = $(this).prev('textarea').data('parentid');
     var reply = $(this).prev('textarea').val();
     $(this).prev('textarea').val('');
     $('#shoutbox_content').find('#reply_textbox_' + parentid).hide();
  
     if (reply.length &gt; 0) {
         alert('save reply ' + parentid);
     }
  });
  
  // when the client hits ENTER on their keyboard
  $('#shoutbox_content').keypress('textarea', function (e) {
     if (e.which == 13) {
         console.log($(this).find('textarea'));
         var test = $(this).attr('data-parentid');
         alert('Enter ' + test);
         $(this).blur();
         $(this).next('#replysend').focus().click();
     }
  });
  </code></pre>
  
  <p>It works but I don't know which ID was send. Has anybody an idea how I can find out in which reply textarea the user pressed Enter?</p>