title: Javascript no longer works after performing AJAX Post
body: <p>Good day. I have been using AJAX post for a while now. I have this javascript code that allows blocks of html codes to be collapsed / expanded when clicked (it is collapsed by default). It works when the form loads for the first time, but once I perform an AJAX post the javascript code doesn't work anymore. I've tried placing the javascript code in the place where the php functions are performed, but that doesn't work either. </p>
  
  <p>I'm not really that well-versed with Javascript or AJAX and I only derived this code from an external source. Any help would be much appreciated.</p>
  
  <p>Javascript:</p>
  
  <pre><code>   &lt;script&gt;
              $(document).ready(function()
              {
                          $('p.content2').hide(); 
                          $('p.content2').addClass('active').next().show(); 
                          $('button.clickThis').click(function()
  
              {
                   if( $(this).next().is(':hidden'))
                      { 
                          $('p.clickThis').removeClass('active').next().slideUp(); 
                  $(this).toggleClass('active').next().slideDown(); 
                  }               
              else
                  {
                  $(this).toggleClass('active').next().slideToggle('slow');
                  }
              return false;
              });
          }); 
  &lt;/script&gt;
  </code></pre>
  
  <p>AJAX Script:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function createTask()
  {if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
  else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
      {
      document.getElementById("resultDiv").innerHTML=xmlhttp.responseText;
      }
    }
  
  var params = 'taskName='+encodeURI(document.getElementById('taskName').value)+'&amp;taskDesc='+encodeURI(document.getElementById('taskDesc').value)+'&amp;btnCreateTask='+encodeURI(document.getElementById('btnCreateTask').value);
  xmlhttp.open("POST","taskProcess.php",true);
  xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-length", params.length);
  xmlhttp.setRequestHeader("Connection", "close");
  xmlhttp.send(params);}
  &lt;/script&gt;
  </code></pre>