indexOf

Returns the index of specified item. Filtered items are excluded from the collection.

Important: While user drags to sort the original item is hidden and the placeholder is appended to the Sortable collection. This is why jQuery's index method might return incorrect results. When the developer wants to find the index of a given item it is recommended to use widget's indexOf method.

Parameters

element jQuery

jQuery object which represents the sortable element.

Returns

Number the index of specified item.

Example - working with indexOf method

<div id="sortable">
    <h4>Sortable List</h4>
    <div>Item1</div>
    <div>Item2</div>
    <div>Item3</div>
</div>

<script>
    $("#sortable").kendoSortable({
        filter: ">div",
        move: function(e) {
            //NOTE: the heading element will be excluded from the
            //collection as it does not match the filter

            //shows the original position of the item
/* The result can be observed in the DevTools(F12) console of the browser. */
            console.log("index of item", this.indexOf(e.item));
            //shows the position where item will be moved to
/* The result can be observed in the DevTools(F12) console of the browser. */
            console.log("index of placeholder", this.indexOf(this.placeholder));
        }
    });
</script>
In this article