jQuery child
JavaScript performance comparison
Info
What's the fastest way to get a child in jQuery? .children(), .next() or :first-child? I know the class-name in advance.
http://www.quora.com/Whats-the-fastest-way-to-get-a-child-in-jQuery
Preparation code
<div id="parent" class="parent">
<div id="child" class="child">
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var p = $('#parent');
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
$('#parent').children() |
|
pending… |
$('#parent').children('.child') |
|
pending… |
$('.child:first-child') |
|
pending… |
$('#parent .child:first-child') |
|
pending… |
$('#parent :first-child') |
|
pending… |
p.children() |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Todd
- Revision 4: published by Marco Rogers and last updated
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 9: published
- Revision 10: published by Matthew Callis
- Revision 11: published
0 comments