Discussion on jquery best performance practices

Source: Internet
Author: User
I haven't written anything for a long time, and the project was coming to an end a few years ago. Recently, I saw an article on the Internet that links to jQuery best practices at the end of the article because I was testing it: contains the wrong variable. For details, refer to the $ (parentID> childClass) on the image. I have compared the two characters to change the size!
Thanks to "No cupid" in the html5 Chinese Web QQ group ".

The third point mentions the relationship between the parent element and the child element and mentions the use case for selecting the child element from the parent element:

The Code is as follows:

$ ('. Child', $ parent)
$ Parent. find ('. child ')
$ Parent. children ('. child ')
$ ('# Parent>. child ')
$ ('# Parent. child ')
$ ('. Child', $ ('# parent '))

In the test case, it is true that the find method using jquery is the fastest, but with a slight modification, another result is obtained $ ('# parent>. child.

In the author's use case, only the object $ ('# parent') is directly cached '); however, when we define the dom id and class attributes as constants and pass them into the test case, another result is displayed.
Author native test page: http://jsperf.com/bell-selector

Tested after modification page: http://jsperf.com/bell-selector/2

At the same time, I can test a piece of code segment that I obtained from the real environment. It is also the fastest way to write $ ('# parent>. child.
Test page: http://jsperf.com/findchildren

From the above results, we can see that the two test results I have given are obviously good performance with a greater than the number selector.

If you see this article or learn more, you can give a description. Other content in the article is a good idea.
Article: http://www.jb51.net/article/28056.htm

The person in the garden who has time and conditions can debug the above operations and provide detailed procedures. I have to wait for the project to finish before I can debug the process.
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.