title: Jquery Sortable on table rows run function on change
body: <p>I have a script that counts the number of rows in a table and assigns a value attribute to an input field. I am adding the draggable plugin Sortable to table rows, what would be the best way to run this script then on document ready, and on change. The first part works, but i am not getting alerted when the table rows change.</p>
  
  <p>this is now my revised code:</p>
  
  <pre><code>function countRows(){
      var i = 0;
      $('#offices td input').each(function(){
          $(this).attr("value", ++i);
      });  
  }
  $(document).ready(countRows);
  
  // Sortable rows
  $('.sorted_table').sortable({
    containerSelector: 'table',
    itemPath: '&gt; tbody',
    itemSelector: 'tr',
    placeholder: '&lt;tr class="placeholder"/&gt;'
  })
  
  $('.sorted_table').children("tbody").sortable({
      stop: function (event, ui) {
          countRows(); // re-number rows after sorting
      }
  });
  </code></pre>