title: jQuery UI Draggable: Stack on Click
body: <p>Is there any way to kick off a <code>draggable</code>'s stack procedure when it is clicked, not just dragged?</p>
  
  <p>I found <a href="http://urbanoalvarez.es/blog/2013/01/21/jqueryui-draggable-bring-stack-element-to-front-on-click/" rel="noreferrer">this</a> solution, which basically tries to just copy the library code. (It is also missing an important piece which I inserted below). Is there not a more elegant solution?</p>
  
  <p>Modifying the author's code, the following solution works:</p>
  
  <pre><code>function bringFront(elem, stack){
      // Brings a file to the stack front
      var min, group = $.makeArray($(stack)).sort(function(a, b) {
          return (parseInt($(a).css("zIndex"), 10) || 0) - (parseInt($(b).css("zIndex"), 10) || 0);
      });
  
      if(group.length &lt; 1) return;
      min = parseInt(group[0].style.zIndex, 10) || 0;
      $(group).each(function(i) {
          this.style.zIndex = min+i;
      });
  
      if(elem == undefined) return;
      $(elem).css({'zIndex' : min+group.length});
  }
  </code></pre>
  
  <p>But it would obviously be better to call the library method somehow.</p>