Js, jQuery sorting, webpage tag sorting, and tag sorting. For more information, see. Js and jQuery sorting implementation:
Key: the simplest way to achieve sorting is
First, read the tag into the object Array Using jQuery.
Sort the object array with js (sort the object array and do not try to directly change the content of the webpage)
Overwrite the tag array on the webpage with the object array content;
// Sort text from short to long
The Code is as follows:
// Sort text from short to long
Var arr_a = new Array ();
Var I = 0;
$ (". Type_list_txt> span: contains ('T')"). parent (). children ("a"). each (function (){
Arr_a [I] = $ (this). clone ();
I ++;
});
For (I = 0; I {
For (j = I + 1; j {
If ($ (arr_a [I]). text (). length> $ (arr_a [j]). text (). length)
{
Temp = arr_a [I];
Arr_a [I] = arr_a [j];
Arr_a [j] = temp;
}
}
}
I = 0;
$ (". Type_list_txt> span: contains ('T')"). parent (). children ("a"). each (function (){
$ (This). replaceWith ($ (arr_a [I]);
I ++;
});