Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an element in ul lists unsortable and undraggable?

An ul list contains some items. The last item must always stay in a static position. I've tried to use cancel option of the .sortable() method, but it doesn't switch off sortable, just dragging.

<ul id="sort">
    <li>Jquery</li>
    <li>MooTools</li>
    <li>Prototype</li>
    <li>YUI</li>
    <li class="last">must stay static (add position button)</li>
</ul>

$('#sort').sortable({
    cancel: '.last'
});

Example fiddle: http://jsfiddle.net/mbarinov/JLZvY/

like image 501
NiLL Avatar asked Nov 14 '11 08:11

NiLL


1 Answers

You can use the items options to specify a selector which excludes items that expose the last class:

$('#sort').sortable({
    items: "li:not(.last)"
});

You will find an updated fiddle here.

like image 151
Frédéric Hamidi Avatar answered Nov 03 '22 01:11

Frédéric Hamidi