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
confirm removed
confirm hidden
confirm detatched
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… |
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 Alex Kahn and last updated
- Revision 2: published by Alex Kahn
- Revision 3: published by Mathias Bynens
- Revision 4: published by tenbits
- Revision 5: published
- Revision 6: published by peke
- Revision 7: published
- Revision 9: published
- Revision 10: published
- Revision 12: published
- Revision 14: published
- Revision 15: published by fghfgh
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 20: published by Felipo Antonoff
- Revision 21: published
- Revision 22: published by Chele Loco
- Revision 23: published by Don
- Revision 24: published
- Revision 25: published
0 comments