Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Sortable - no dragging past last list item

I have an unsorted list (UL) that contains sortable list items (LI), except for the last list item. I need the last item to stay at the end of the list:

<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 2</li>
    <li>Last item</li><!-- Should always be the last item -->
</ul>

I'm using jQuery Sortable for sorting the list items.

Does anyone know a good way to prevent list items from being dragged past the last list item?

like image 419
Prutswonder Avatar asked Jan 25 '12 09:01

Prutswonder


1 Answers

You can pass a selector that excludes the last item in the items option:

$("ul").sortable({
    items: "li:not(:last-child)"
});
like image 149
Frédéric Hamidi Avatar answered Sep 25 '22 23:09

Frédéric Hamidi