teelou teelou - 1 year ago 60
jQuery Question

How to exclude an element from being dragged in sortable list?

How can I exclude an element from sortable list? For instance, there is an element with class name 'note' that I don't want to be draggable?

<ul class="sortable">

<li id="item_3">Item 3</li>
<li id="item_4">Item 4</li>
<li id="item_5">Item 5</li>

<p class="note">This is a note only</p>

jquery ui sortable, jquery
obviously does not work...

$(function() {
$( ".sortable:not(.note)" ).sortable(

Answer Source

You need to use cancel.

See working example here.


$(function() {
    $('.sortable').sortable({ cancel: '.note' });

As @Zephyr points out, this let's you re-arrange the position by dragging the siblings, if you want to avoid that, use owise1 approach:

    items : ':not(.note)'