jQuery UI & Draggable: Sortable

This entry is part 4 of 11 in the series jQuery UI Draggable

jQuery UI Draggable + Sortable

Draggables are built to interact seamlessly with sortable.

We have $(“ul, li”).disableSelection() so that when the mouse is moved over the boxes, the text will not be selected.

When setting helper: ‘clone’, then the element will be cloned and the clone is the element that is going to be dragged.

The revert: ‘invalid’ will prevent the draggable element to return to its original postion once it is dragged and positioned in the sortable boxes.

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <title>jQuery UI Draggable + Sortable</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.9.1.js"></script>
    <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <link rel='stylesheet' href='http://codecrawl.com/code/jqueryui/jqueryui_style.css'>
        ul {
            list-style-type: none;
            margin: 0;
            padding: 0;
            margin-bottom: 10px;

        li {
            margin: 5px;
            padding: 5px;
            width: 150px;
        $(function () {
                revert: true
                connectToSortable: "#sortable",
                helper: "clone",
                revert: "invalid"
            $("ul, li").disableSelection();

    <li id="draggable" class="ui-state-highlight">Drag me down</li>

<ul id="sortable">
    <li class="ui-state-default">Item 1</li>
    <li class="ui-state-default">Item 2</li>
    <li class="ui-state-default">Item 3</li>
    <li class="ui-state-default">Item 4</li>
    <li class="ui-state-default">Item 5</li>

Try The Code
Series Navigation<< jQuery UI & Draggable: Constrain movement
jQuery UI & Draggable: Visual Feedback >>

Leave a comment

Leave a Reply