jQuery .remove
vs. .hide
vs. detach
JavaScript performance comparison
Preparation code
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="remove-me">confirm removed</div>
<div id="hide-me">confirm hidden</div>
<div id="detach-me">confirm detatched</div>
<script>
function init() {
// The magic init() function will be executed once before every test
// Still not perfect, but definitely better
$('<div id="remove-me" />').appendTo('body');
window.$element = $('#hide-me').show();
if (window.$detached != null) {
window.$detached.appendTo('body');
}
}
</script>
Preparation code output
<div id="remove-me">confirm removed</div>
<div id="hide-me">confirm hidden</div>
<div id="detach-me">confirm detatched</div>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
.remove()
|
|
pending… |
.hide()
|
|
pending… |
.detach()
|
|
pending… |
style.display
|
|
pending… |
.css()
|
|
pending… |
.css() without lookup
|
|
pending… |
style.display with jQuery
|
|
pending… |
style.display without lookup
|
|
pending… |
style.display with getElementById && jQuery
|
|
pending… |
style.display with querySelector
|
|
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.
- Revision 1: published Alex Kahn and last updated
- Revision 2: published Alex Kahn
- Revision 3: published Mathias Bynens
- Revision 4: published tenbits
- Revision 5: published
- Revision 6: published peke
- Revision 7: published
- Revision 9: published
- Revision 10: published
- Revision 12: published
- Revision 14: published
- Revision 15: published fghfgh
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 20: published Felipo Antonoff
- Revision 21: published
- Revision 22: published Chele Loco
- Revision 23: published Don
- Revision 24: published
- Revision 25: published
- Revision 27: published
- Revision 28: published
- Revision 29: published
- Revision 30: published
- Revision 33: published Schalk Neethling
- Revision 34: published gotomanners
- Revision 35: published
- Revision 36: published
- Revision 37: published
- Revision 38: published
- Revision 39: published Heavensrevenge
- Revision 40: published
- Revision 41: published
- Revision 42: published
- Revision 43: published
- Revision 44: published agm
- Revision 45: published
- Revision 46: published
- Revision 47: published
- Revision 48: published Dan
- Revision 49: published
- Revision 50: published
- Revision 51: published Anu
0 Comments