title: jQuery sortable obtain 2 elements being swapped
body: <p>I cannot find out how to obtain destination element with jQuery UI sortable.</p>
  
  <pre><code>    $("#pages").sortable({
          opacity: 0.6,
          update: function(event, ui) {
              var first = ui.item; // First element to swap
              var second = ???? // Second element to swap
              swapOnServer(first, second);
          }
      });
  </code></pre>
  
  <p>All the options I've tried point to the element being dragged, but not the one it is swapped with: <code>ui.item[0]</code>, <code>event.srcElement</code>, <code>event.toElement</code>.</p>
  
  <p>Additionally, <code>this</code> points to the LIST (OL) element.</p>
  
  <p>Saying <strong>second</strong> I mean following:</p>
  
  <p>Original order is:</p>
  
  <blockquote>
    <p>| 0 | <strong>1</strong> | 2 | <strong>3</strong> |</p>
  </blockquote>
  
  <p>We drag element 1 and drop it in position 3. Which will end up with:</p>
  
  <blockquote>
    <p>| 0 | <strong>3</strong> | 2 | <strong>1</strong> |</p>
  </blockquote>
  
  <p>So the first element is 1 and the second is 3 (WRONG! See below).</p>
  
  <p><strong>UPDATE: I have realised that I got it wrong.</strong> The new order in this case will be.</p>
  
  <blockquote>
    <p>| 0 | 2 | 3 | <strong>1</strong> |</p>
  </blockquote>
  
  <p><strong>As a result my question does not really makes sense. Thanks everybody for the help. I'll mark vote and mark an answer.</strong></p>
  
  <p>So the question is how to obtain the second element here?</p>
  
  <hr>
  
  <p>THE CURRENT WORKAROUND (as there is no term as <em>swapping</em> in sortable) is below. It uses temporary array with orders.</p>
  
  <pre><code>    var prevPagesOrder = [];
      $("#pages").sortable({
          start: function(event, ui) {
              prevPagesOrder = $(this).sortable('toArray');
          },
          update: function(event, ui) {
              var currentOrder = $(this).sortable('toArray');
              var first = ui.item[0].id;
              var second = currentOrder[prevPagesOrder.indexOf(first)];
              swapOnServer(first, second);
          }
      });
  </code></pre>
  
  <p>Thanks,<br>
  Dmitriy.</p>