Js,jquery sorting implementation Code, Web page tag sorting implementation, label sorting _javascript tips

Source: Internet
Author: User
Implementation of Js,jquery sorting:
Important: The easiest way to achieve a sort is to
First read the tags in jquery into the object array
Sort the array of objects with JS (sort on an array of objects, do not try to directly change the content of the Web page directly)
Overwrites the array of labels on the Web page with the object array content;
Sort from text short to long
Copy Code code as follows:

Sort from text short to long
var arr_a=new Array ();
var i=0;
$ (". Type_list_txt > Span:contains (' t-shirts ')"). Parent (). Children ("a"). each (function () {
arr_a[i]=$ (This). Clone ();
i++;
});
for (i=0; i<arr_a.length;i++)
{
for (j=i+1;j<arr_a.length;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-shirts ')"). Parent (). Children ("a"). each (function () {
$ (this). ReplaceWith ($ (arr_a[i]));
i++;
});

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.