title: jQuery click function only activating first element
body: <p>I am building a system to manage tickets. Each ticket has a 'Start', 'Pause', 'Complete', and 'Edit' button. The buttons are generated by using PHP which pulls the tickets from a database and loops through the code for each ticket. Here is the PHP/HTML:</p>
  
  <pre><code>        foreach ($ticket as $print) {
              echo '&lt;div id="ticketDiv"&gt;';
              echo '&lt;tr class="myTickets" id="' . $print-&gt;id . '" &gt;';
                      echo '&lt;td id="myTickets_business_name_column"&gt;' . $print-&gt;business_name . '&lt;/td&gt;';
                      echo '&lt;td id="myTickets_subject_column"&gt;' . $print-&gt;subject . '&lt;/td&gt;';
                      echo '&lt;td id="myTickets_status_column"&gt;';
                          if ($print-&gt;status == 'Begin'){
                              echo 'Open';
                          }
                          else {
                              echo $print-&gt;status;
                          }
                      echo '&lt;/td&gt;';
              echo '&lt;/tr&gt;';
              echo '&lt;tr id="ticketButtons' . $print-&gt;id . '" class="ticketButtonsRow" style="display:none;"&gt;';
                      echo '&lt;td&gt;&lt;/td&gt;';
                      echo '&lt;td&gt;';
                              echo '&lt;div class="ticketButtons"&gt;';
                                  if ($print-&gt;status == 'Paused')
                                  {
                                      echo '&lt;button value="' . $print-&gt;id . '" class="StartButton"&gt;Start&lt;/button&gt;';
                                  }
                                  elseif ($print-&gt;status == 'Open' or 'Begin')
                                  {
                                          echo '&lt;button value="' . $print-&gt;id . '" class="PauseButton"&gt;Pause&lt;/button&gt;';
                                  }
                                  echo '&lt;button value="' . $print-&gt;id . '" class="CompleteButton"&gt;Complete&lt;/button&gt;';
                                  echo '&lt;a href="' . site_url( 'edit-ticket' ) . '?id=' . $print-&gt;id . '"&gt;&lt;button id="editButton" value="' . $print-&gt;id . '" class="EditButton"&gt;Edit&lt;/button&gt;&lt;/a&gt;';
                              echo '&lt;/div&gt;';
                      echo '&lt;/td&gt;';
                      echo '&lt;td&gt;&lt;/td&gt;';
              echo '&lt;/tr&gt;';
          }
  </code></pre>
  
  <p>For each ticket they have a unique ID that is generated from the database. Each button has the value of the unique ID for that ticket. When you click any of the buttons (Start, Pause, etc) the jQuery then takes over to update the database. It takes the value of the button and passes it along to the submit form that then runs the query to update the database. </p>
  
  <p>The problem I'm having is when there are multiple tickets in a list with the same status (Open or Paused) and you click a Start/Pause button for any of the tickets below the first one, it passed along the ID of the first ticket and not the one you clicked.</p>
  
  <p>Here is my jQuery for Start and Pause:</p>
  
  <pre><code>/* 
  ** Ticket updating buttons
  */
  $(document).ready(function($){
      /* Toggles ticket buttons for each ticket */
      $(".myTickets").click(function() {
          var ticket_id = $(this).attr('id');
          $('.ticketButtonsRow').hide();
          $(this).next('#ticketButtons' + ticket_id).slideToggle(100);
      });
  
      /* When the start button is clicked - the following below is executed */
      $(".StartButton").click(function(e) {
  
          /* Pulls ticket ID from button clicked */
          var ticket_id = $(".StartButton").val();
  
          /* Hides the ticket buttons on click */
          $('#ticketButtons' + ticket_id).hide(100);
  
          /* Places data into an array */
          var dataString = 'start=' + ticket_id;
  
          /* Enables data logging in the console */
          console.log(dataString);
  
          /* Where the magic happens */
          $.ajax({
                 type: "POST",
                 url: 'submit-data',
                 data: dataString,
                 cache: false,
                 success: function(data)
                 {
                     /* Reloads the page after success */
                      location.reload();
  
                 }
               });
      });
  
  /* When the pause button is clicked - the following below is executed */
  $(".PauseButton").on('click', function(e) {
      console.log($(this).text());
      var ticket_id = $(".PauseButton").val();
  
      /* Hides the ticket buttons on click */
      $('#ticketButtons' + ticket_id).hide(100);
  
      /* Shows the note form */
      $("#addNoteFormDiv").show(200);
  
      /* When cancel button is clicked close notes and cancel pause action */
      $("#notesCancelButton").click(function() {
          $("#addNoteFormDiv").hide(200);
      });
  
      /* After notes has been added and submit button clicked */
      $("#notesDoneButton").click(function(e) {
  
          $("#addNoteFormDiv").hide(200);
  
          var notes = $("#addNotes").val();
          var employee_id = $("#notes_employee_id").val();
  
          /* Places data into an array */
          var dataString = 'pause=' + ticket_id + '&amp;notes=' + notes + '&amp;employee_id=' + employee_id;
  
          /* Enables data logging in the console */
          console.log(dataString);
  
          /* Where the magic happens */
          $.ajax({
                 type: "POST",
                 url: 'submit-data',
                 data: dataString,
                 cache: false,
                 success: function(data)
                 {
                     /* Reloads the page after success */
                      document.getElementById("addNoteForm").reset();
                      //location.reload();
                 }
               });
  
          /* Prents the execuation of the actual submit of the form */
          e.preventDefault();
      });
  });
  return false;
  </code></pre>
  
  <p>Also, you will see some code in there for a slideToggle. That is for hiding and showing the buttons when you click on a ticket.</p>