2

I have an sortable list but I would like to disable the first item, so that the input field cannot be moved.

Here is the list:

<ul id="sortable" class="connectedSortable">
    <input name="name1" class="inputfield" type="text" maxlength="30">
    <li>first sort item</li>
    <li>second sort item</li>
</ul>

And the js:

$("#sortable:not(:first-child)").sortable({
            connectWith : ".connectedSortable"
        });

I tried to solve this with the :not(:first-child) but it is not working... Does someone know how to do this?

Thanks!

1
  • 1
    You also can't have items inside of a <ul> that aren't inside of <li> tags Commented Nov 7, 2012 at 18:20

3 Answers 3

4

If you fix your HTML so that your input is properly wrapped in a list item, then you can try using the sortables's items option:

$("#sortable").sortable({
    items: "> li:gt(0)", 
    connectWith: ".connectedSortable"
});​

jsFiddle example

Sign up to request clarification or add additional context in comments.

Comments

4

How about this?

$( "#sortable" ).sortable({
    items: '> li'   
});

Demo

Comments

1

Your HTML isn't valid, since you cannot have HTML inside a <ul> that isn't also inside of the <li>'s.

var _input = $("#sortable :first-child");

$('#sortable').before(_input); // move it outside of the UL
$('#sortable').sortable();

http://jsfiddle.net/nF7yW/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.