Js, jQuery sorting implementation code, webpage tag sorting implementation, tag sorting _ javascript skills

Source: Internet
Author: User
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 ++;
});

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.