title: javascript serialize on appended divs
body: <p>Is it possible to serialize appended forms in jquery? I tried both button.on(click) and form.on(submit), but got a problem. When I use the onclick button it gives me an undefined serialization. When I use form submit, it gives me nothing.</p>
  
  <p>Here's my JS Code:</p>
  
  <pre><code>function main_login(){
  
  $('.main-login').click(function(){
  var adpas = prompt("Enter password: ");
  if(adpas !== null){
      $.ajax({
          type: 'post',
          url: 'init.php',
          data: {data: adpas},
          success: function(data){
      if(data == "success"){
              $('#main-note').css('display', 'initial');
              $('#main-note').append(''+
  '&lt;div id="note_app" style="height: 450px; width: 700px; background-color: white; border-radius: 10px;"&gt;'+
  '&lt;div style="height:12px; width:15px; border-radius:10px; background: linear-gradient(red, white);" align="center"&gt;&lt;a href="index.html" onclick="close_window()" style="text-decoration: none; cursor: pointer;"&gt;X&lt;/a&gt;&lt;/div&gt;'+
  '&lt;center&gt;&lt;form action="" id="formmsg" method="post"&gt;&lt;input type="text" id="note-title" style="width: 98%; height: 20px; font-size:16px"/&gt;'+
  '&lt;textarea id="note-texts" style="width: 98%; height: 400px; resize: none;"&gt;&lt;/textarea&gt;&lt;/center&gt;'+
  '&lt;input type="submit" value="Encode Lecture" name="btn-lecture" id="btn-lecture"&gt;&lt;/form&gt;&lt;/div&gt;');
  
      $('#formmsg').on('submit', function() {
          alert($(this).serialize());
      });
  
      }
  
      else{
          alert('You don\'t have any administrative rights to open this link.');
      }
  
  
  
          }
      });
  
  }
  });
  
  }
  </code></pre>
  
  <p>Another question:
  It seems that every time I  successfully click "main-login class", it gives me the same number of divs it is clicked. Is there anyway to make the button trigger only once, only if the password was accepted and successful?</p>
  
  <p>Tried jQuery.one(); it worked but both for successful and failed login.</p>
  
  <p>Thanks in advance.</p>