3

Let say there are 3 divs Div1, Div2, Div3 and all have the class "ui-selected"

To iterate the div selection you can use something like below

$(".ui-selected").each(...)

The above iteration, references each div in the same sequence as they are added to the Document.

How do we sort the selection.

For e.g if Div1 represents a value of 30, Div2 represents value of 10 and Div3 a value of 40

the iteration when sorted should be as

Div2 , Div1 and Div3.

Right now the list iterates in the order of how they belong in the Doc model.

Is there a way to sort the jquery selection?

1 Answer 1

9

Assuming you have a way to know the "value" of each div, you can use the sort method.

$(".ui-selected").sort(function(a,b){
    //sorting logic here
    }).each(...);
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.