开发者

jquery selector - how to sort the iterated objects

Let say there are 3 divs Div1, Div2, Div3 and a开发者_开发问答ll 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?


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜