title: AJAX not "capturing" event without refresh
body: <p>I'm kind of new to this so please bear with me...</p>
  
  <p>Let's say I have this javascript code</p>
  
  <pre><code>$(document).ready(function() {
      $("a").click(function() {
          alert("Hello world!");
      });
  });
  </code></pre>
  
  <p>The way I understand it, this code will "capture" any link selection and post an alert box.  Normally this works fine.</p>
  
  <p>Now, on the same page I also have a table, and on submit, I'm capturing the form submit and using JQuery to add the row to the users display while the data is sent to the server.  </p>
  
  <p>Here's the code to intercept the post request (mostly taken from <a href="http://railscasts.com/episodes/136-jquery" rel="nofollow noreferrer">Railscasts #136</a>)</p>
  
  <pre><code>jQuery.ajaxSetup({
      'beforeSend': function(xhr) {
          xhr.setRequestHeader("Accept", "text/javascript")
      }
  })
  
  jQuery.fn.submitWithAjax = function() {
      this.submit(function() {
          $.post(this.action, $(this).serialize(), null, "script");
          return false;
      })
      return this;
  };
  
  $(document).ready(function() {
      $("#new_ride_form").submitWithAjax();
  })
  </code></pre>
  
  <p>Here's the code to render the partial...</p>
  
  <pre><code>$("#add_new_ride").before("&lt;%= escape_javascript(render(:partial =&gt; @ride)) %&gt;");
  $("#ride_&lt;%=@ride.id %&gt;").effect("highlight", {color: '#aaffaa'}, 2000);
  $("#new_ride_form")[0].reset();
  </code></pre>
  
  <p>Here's the code to create a link in one of the table cells generated by the partial</p>
  
  <pre><code>&lt;td&gt;&lt;%= link_to  'remove', ride_url(ride),
     :id =&gt; :destroy_ride,
     :method =&gt; :delete,
     :href =&gt; delete_ride_url(ride) %&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>Now when I submit the form, then click on the 'remove' link in the newly created table row, it simply submits the delete request. The javascript to create the 'Hello World' alert box is not executed.</p>
  
  <p>If however, I submit the form, create the new table row, <em>then manually refresh the page</em>, before clicking the 'remove' link in the newly created table row, the the 'Hello World' alert box appears as expected.</p>
  
  <p>What's going on here where I need to manually refresh before getting the expected behavior?</p>
  
  <p>Is there a "document.ready" event or something I need to trigger after using AJAX to add the table row in order to tell the code that "hey, there's some new stuff over here you need to watch for".</p>
  
  <p>Thanks!</p>
  
  <p>By the way, I'm coding in Rails and JQuery, but I'm not really sure it matters.</p>