Access checked checkboxes
JavaScript performance comparison
Info
Which way is the best to get the checked checkboxes and radioboxes?
Preparation code
<p>
<form action="" id="testform">
<div>
<label ><input type="text" name="inputText1"/></label>
<input type="text" name="inputText2"/>
<input type="text" name="inputText3"/>
<input type="text" name="inputText4"/>
<input type="text" name="inputText5"/>
<label><input type="checkbox" name="checkboxGroup1[]"/></label>
<input type="checkbox" checked name="checkboxGroup1[]"/>
<input type="checkbox" name="checkboxGroup1[]"/>
<input type="checkbox" name="checkboxGroup1[]"/>
<input type="checkbox" checked name="checkboxGroup1[]"/>
<input type="checkbox" name="checkboxGroup2[]"/>
<input type="checkbox" checked name="checkboxGroup2[]"/>
<input type="checkbox" name="checkboxGroup2[]"/>
<input type="checkbox" checked name="checkboxGroup2[]"/>
<input type="checkbox" name="checkboxGroup2[]"/>
<label >text<input type="radio" name="radioboxGroup1"/></label>
<input type="radio" name="radioboxGroup1"/>
<input type="radio" name="radioboxGroup1"/>
<input type="radio" name="radioboxGroup1"/>
<input type="radio" checked name="radioboxGroup1"/>
<input type="password" name="pass"/>
<input type="password" name="pass"/>
<input type="radio" name="radioboxGroup2"/>
<input type="radio" name="radioboxGroup2"/>
<input type="radio" checked name="radioboxGroup2"/>
<input type="radio" name="radioboxGroup2"/>
<input type="radio" name="radioboxGroup2"/>
<button type="submit">submit</button>
</div>
</form>
</p>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Simple selector |
|
pending… |
Specifying it's an input |
|
pending… |
Be specific |
|
pending… |
get the id and then the checked ones |
|
pending… |
Now also specify input |
|
pending… |
Everything separated |
|
pending… |
simple querySelectorAll |
|
pending… |
complete querySelectorAll |
|
pending… |
getElementById + unspecific querySelectorAll |
|
pending… |
getElementById + querySelectorAll |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments