Fixing JQuery UI 1.7.3 Draggable bug

08 December 2011 on Javascript, JQuery

Well, I was playing with a project this week and I was kind of stuck on an old JQuery ui version. Turns out dragging images around, using Chrome, was, at the same time, selecting the image, messing all the stuff around. Something like this:

<script type="text/javascript" language="javascript" charset="utf-8">
  $("img").draggable();
</script>

At the newest version of JQuery ui, the draggable stuff was working normally on Chrome, so I did a research and after an entire day the solution showed up. Fixing it is pretty simple, you should just bind the 'dragstart' on the image and prevendDefault().

<script type="text/javascript" language="javascript" charset="utf-8">
  $("img").draggable();
  $('img').bind('dragstart', function(event) { event.preventDefault() });
</script>