Home > Web Front-end > JS Tutorial > Discussion on jquery performance best practices and seeking advice_jquery

Discussion on jquery performance best practices and seeking advice_jquery

WBOY
Release: 2016-05-16 17:54:44
Original
1018 people have browsed it

The reason is that when I tested: I brought in the wrong variables. For details, you can check $(parentID > childClass) on the picture. I directly compare the two characters and change the size!
Thanks to "Missing Cupid" in the QQ group of html5 Chinese website.

The third point mentions the relationship between parent elements and child elements and mentions the use case of selecting child elements from parent elements:

Copy code The code is as follows:

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

In the test cases given, it is indeed the fastest to use jquery's find method, but after a slight modification, another result $('#parent > .child') was obtained.

In the author's use case, the object $('#parent') is directly cached; but when we define the dom's id and class attributes as constants and pass them into the test case, what I said appears. Another result.
The author’s original test page: http://jsperf.com/bell-selector
Result screenshot:
Discussion on jquery performance best practices and seeking advice_jquery
The modified test page: http://jsperf.com/bell- selector/2
Screenshot of results:
Discussion on jquery performance best practices and seeking advice_jquery

At the same time, give me the test I did on a piece of code snippet I took out of the real environment, also $('#parent > . child') is the fastest way to write it.
Test page: http://jsperf.com/findchildren
Result screenshot:
Discussion on jquery performance best practices and seeking advice_jquery
As you can see from the above result screenshot, the two test results I gave are obviously using The performance of the greater than sign selector is better.

If you see this article or know the details, please give us an explanation. Everything else in the article is a good point.
Article: http://www.jb51.net/article/28056.htm

Whoever has the time and conditions in the garden can debug each of the above operations. Give detailed process instructions. I have to wait until the project in hand is finished before I have time to debug this process.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template