title: How to access dynamic id tag with jquery
body: <p>I'm trying to update the paragraph tag in foreach with jquery selector in my second ajax call. I made the id tag unique by setting it to <code>id="spots_,+item.id</code>" but don't know how to access the dynamic id tag outside the foreach loop. I keep getting "id is not defined" error. Thought maybe a global variable would work but no success.</p>
  
  <pre><code>//ajax form the get available times to play
  $('#form').submit(function(){
  $.ajax({
    url: $('#form').attr('action'),
    type: 'POST',
    data : $('#form').serialize(),
       success: function(response){
        $.each(JSON.parse(response), function(i, item) {
            var jdate = $('#date').val();
  
          $('&lt;tr&gt;').html("&lt;td&gt;" + item.time + "&lt;/td&gt;&lt;td&gt;" + '&lt;form class="insideForm" action="/reservations/getSpots" accept-charset="utf-8"  method=""&gt;'  + '&lt;input type="text" name="jtime" value="' + item.time + '"' + "/&gt;"  + '&lt;input type="text" name="jdate" value="' + jdate + '"' + "&gt;" + '&lt;input type="submit" class="btn btn-primary" value="Spots"&gt;' +  '&lt;/form&gt;' + "&lt;/td&gt;&lt;td&gt;" + "Spots:" + '&lt;p class="spots" id="spots_' + id + '"'+ "&gt;" + '&lt;div id="spots"&gt;&lt;/div&gt;' + '&lt;/p&gt;'  +  "&lt;/td&gt;").appendTo('#availableTimes');
          });//end loop                   
  
      //ajax form the get available spots/seats 
  $('.insideForm').submit(function(){
  var form = $(this).closest('form');
  
  $.ajax({
    url: $(this).attr('action'),
    type: 'POST',
    data : $(this).serialize(),
            success: function(response){        
          $('#spots_'+id).html(response);         
        }//end success      
      });
     return false;
  });                    
    }//end success
  });
  return false;
  });//end ajax time form
  </code></pre>