Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of elements in a JQuery Sortable list

The API of JQuery Sortable isn't clear on how to retrieve the number of elements in a sortable list. The reason I want the number of elements, is because I want to set the position of a widget to the end of the sortable list. I know there is an append function, but I have my own logic to manipulate the sortable list.

Does someone know how to do this?

like image 743
John Hendrik Avatar asked Jan 10 '13 09:01

John Hendrik


3 Answers

This should do it:

$('#sortable li').length;

since $(foo) returns either a jQuery object or an array of jQuery objects, depending on the selector foo, you can use the .length attribute.

like image 82
Zim84 Avatar answered Nov 12 '22 10:11

Zim84


you could use toArray method and check the length of the result array

like image 44
Dziad Borowy Avatar answered Nov 12 '22 09:11

Dziad Borowy


I think this might not be implemented in the jQuery sortable plugin (I haven't checked though), because just standard jQuery can count your list items.

for example:

var count = $("#myList li).length

gets you the number of records in the list <ul id="myList">

like image 2
JDM Avatar answered Nov 12 '22 09:11

JDM