Skip to content

Draggable list

This script has approximately 1 KB

jSuites.sorting is a compact JavaScript solution for creating user-friendly sortable lists. It allows for easy reordering of list items through a simple drag-and-drop interface.

The plugin offers several event-driven methods to interact with the draggable elements:

MethodDescription
ondragstartCalled when dragging starts.
ondragendCalled when dragging ends.
ondropCalled upon dropping an item. The method signature is ondrop(DOMElement, int from, int to, DOMElement, DOMElement, mouseEvent).

Below is an example demonstrating how to use jSuites.sorting to make a list of items draggable:

  • Test 1
  • Test 2
  • Test 3
  • Test 4
<html>
<script src="https://jsuites.net/v6/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v6/jsuites.css" type="text/css" />

<ul id='draggable-elements' class='cursor'>
    <li>Test 1</li>
    <li>Test 2</li>
    <li>Test 3</li>
    <li>Test 4</li>
</ul>

<script>
jSuites.sorting(document.getElementById('draggable-elements'), {
    ondrop: function() {
        console.log(arguments);
    }
});
</script>

<style>
#draggable-elements li {
    background-color: #FFF;
    padding: 3px;
    margin-bottom: 3px;
    border-radius: 3px;
    font-size: 16px;
}
</style>
</html>

jsfiddle working example