id vs class vs tag vs pseudo vs. attribute selectors
JavaScript performance comparison
Info
Comparing the performance difference of varied jQuery 1.7 selectors. With a few little test of grabbing the same using the lovely DOM. The dom tests will have to live with the fact that jQuery has been loaded into the page.
This test page contains some dummy HTML (from htmlipsum.com) just to give the page some weight, make the selectors work a little bit.
Note that the "Tag" selector is selecting a tag that happens to be unique in the page just to be fair.
Preparation code
<style type="text/css">
.bar { display: none; }
</style>
<div id="cheese">
<h1>
HTML Ipsum Presents
</h1>
<p>
<strong>
Pellentesque habitant morbi tristique
</strong>
senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam,
feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam
egestas semper.
<em>
Aenean ultricies mi vitae est.
</em>
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra.
Vestibulum erat wisi, condimentum sed,
<code>
commodo vitae
</code>
, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros
ipsum rutrum orci, sagittis tempus lacus enim ac dui.
<a href="#">Donec non enim</a>
in turpis pulvinar facilisis. Ut felis.
</p>
<h2>
Header Level 2
</h2>
<ol>
<li>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</li>
<li>
Aliquam tincidunt mauris eu risus.
</li>
</ol>
<blockquote id="foo" class="bar" name="baz">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in
mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa.
Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus
turpis elit sit amet quam. Vivamus pretium ornare est.
</p>
</blockquote>
<h3>
Header Level 3
</h3>
<ul>
<li>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</li>
<li>
Aliquam tincidunt mauris eu risus.
</li>
</ul>
<pre>
<code>
#header h1 a { display: block; width: 300px; height: 80px; }
</code>
</pre>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
Preparation code output
HTML Ipsum Presents
Pellentesque habitant morbi tristique
senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam,
feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam
egestas semper.
Aenean ultricies mi vitae est.
Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra.
Vestibulum erat wisi, condimentum sed,
commodo vitae
, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros
ipsum rutrum orci, sagittis tempus lacus enim ac dui.
Donec non enim
in turpis pulvinar facilisis. Ut felis.
Header Level 2
 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
 Aliquam tincidunt mauris eu risus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.
Header Level 3
 Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
 Aliquam tincidunt mauris eu risus.
#header h1 a { display: block; width: 300px; height: 80px; }
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test  Ops/sec  

jQuery ID 

pending… 
jQuery Tag 

pending… 
jQuery Class 

pending… 
jQuery attribute 

pending… 
jQuery Pseudoselector 

pending… 
DOM Get Element By Id 

pending… 
DOM Get Element By Tag 

pending… 
Get Elements by Class Name 

pending… 
Get Element By Name Attribute 

pending… 
Get Element By Attribute 

pending… 
jQuery Element limited scope 

pending… 
jQuery Element limited scope another way 

pending… 
DOM Element limited scope 

pending… 
AltPseudo Selector (uses dom function/regex etc) 

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
 Revision 2: published by Scott Kosman
 Revision 3: published
 Revision 4: published
 Revision 5: published by Jozef
 Revision 6: published
 Revision 7: published
 Revision 8: published
 Revision 9: published
 Revision 10: published by Rob
 Revision 11: published
 Revision 12: published by Ben Plum
 Revision 13: published
 Revision 14: published
 Revision 15: published
 Revision 16: published by Felipe
 Revision 17: published by Chris McKee
 Revision 18: published by Mohnish Thallavajhula
 Revision 19: published
 Revision 20: published
 Revision 21: published
 Revision 22: published
 Revision 23: published
 Revision 24: published by Lennon Carvalho
 Revision 26: published by Levi
 Revision 27: published
 Revision 28: published
 Revision 29: published
 Revision 30: published
 Revision 31: published
 Revision 32: published
 Revision 33: published
 Revision 34: published by fafdsfdsgds
 Revision 36: published
 Revision 37: published by Scott Kosman
 Revision 38: published
 Revision 39: published
 Revision 40: published
 Revision 41: published
 Revision 42: published
 Revision 43: published by PeterOak
 Revision 44: published by PeterOak
 Revision 45: published by leo
 Revision 46: published
 Revision 47: published
 Revision 48: published by Eamon Nerbonne
 Revision 49: published
 Revision 50: published
 Revision 51: published
 Revision 52: published by Todd Anglin
 Revision 53: published
 Revision 54: published by Sujay
 Revision 55: published by Emilis
 Revision 57: published
 Revision 59: published
 Revision 60: published
 Revision 61: published by Anas Nakawa
 Revision 64: published
 Revision 68: published
 Revision 69: published
 Revision 70: published
 Revision 74: published
 Revision 76: published by Todd Anglin
 Revision 77: published
 Revision 78: published
 Revision 79: published
 Revision 80: published
 Revision 81: published
 Revision 82: published
 Revision 83: published
 Revision 84: published
 Revision 87: published
 Revision 88: published
 Revision 89: published
 Revision 92: published
 Revision 93: published
 Revision 94: published
 Revision 95: published
 Revision 96: published by gb
 Revision 98: published
 Revision 99: published
 Revision 100: published by Rain Kesküla
 Revision 101: published by Beau Smith
 Revision 102: published
 Revision 103: published
 Revision 104: published by Dmitriy
 Revision 105: published
 Revision 106: published
 Revision 107: published
 Revision 108: published
 Revision 110: published by With JQ
 Revision 111: published
 Revision 112: published
 Revision 113: published
 Revision 114: published
 Revision 118: published
 Revision 120: published
 Revision 121: published
 Revision 122: published by Tim Pietrusky
 Revision 124: published
 Revision 125: published by snekse
 Revision 126: published by Puah Hock Leng
 Revision 127: published
 Revision 128: published
 Revision 129: published by eric
 Revision 130: published
 Revision 131: published
 Revision 132: published
 Revision 133: published
 Revision 134: published
 Revision 135: published
 Revision 136: published by josser
 Revision 137: published by josser
 Revision 138: published by og
 Revision 140: published by amrutha
 Revision 141: published
 Revision 142: published by Christian Oestreich
 Revision 143: published
 Revision 144: published by John Du Hart
 Revision 145: published
 Revision 146: published
 Revision 147: published
 Revision 148: published by Adam
 Revision 149: published
 Revision 150: published
 Revision 151: published
 Revision 153: published
 Revision 154: published
 Revision 156: published
 Revision 158: published
 Revision 159: published
 Revision 162: published
 Revision 163: published
 Revision 164: published
 Revision 165: published by przemek
 Revision 166: published
 Revision 168: published
 Revision 169: published
 Revision 170: published
 Revision 171: published
 Revision 172: published
 Revision 173: published
 Revision 174: published
 Revision 179: published
 Revision 180: published
 Revision 181: published by Steve Yang
 Revision 182: published
 Revision 183: published
 Revision 184: published
 Revision 185: published
 Revision 186: published
 Revision 187: published
 Revision 188: published by Keith Chu
 Revision 189: published
 Revision 190: published
 Revision 193: published
 Revision 194: published
 Revision 195: published
 Revision 196: published by Keith Chu
 Revision 197: published
 Revision 198: published
 Revision 199: published
 Revision 200: published
 Revision 206: published
 Revision 212: published
 Revision 213: published
 Revision 214: published
 Revision 221: published
 Revision 223: published
 Revision 225: published
 Revision 234: published
 Revision 236: published
 Revision 238: published
 Revision 240: published
 Revision 244: published
 Revision 245: published
 Revision 252: published
 Revision 253: published
 Revision 254: published by Patrice
 Revision 256: published
 Revision 257: published
 Revision 258: published
 Revision 259: published
 Revision 260: published
 Revision 261: published
 Revision 262: published
 Revision 263: published
 Revision 264: published
 Revision 265: published
 Revision 266: published
 Revision 267: published by bobbywow
 Revision 268: published
 Revision 269: published by Todd Anglin
 Revision 271: published by querySe
 Revision 275: published by Julien
 Revision 276: published
 Revision 277: published
 Revision 278: published
 Revision 279: published
 Revision 280: published
 Revision 285: published
 Revision 286: published
 Revision 287: published by Erik
 Revision 290: published
 Revision 291: published
 Revision 292: published
 Revision 294: published by Andrew
 Revision 295: published by evilive
 Revision 296: published by Shashaank
 Revision 297: published by shin
 Revision 298: published
 Revision 299: published
 Revision 300: published
 Revision 301: published
 Revision 302: published
 Revision 303: published
 Revision 304: published
 Revision 305: published
 Revision 306: published
 Revision 309: published
 Revision 310: published by sin
 Revision 311: published by Andrey
 Revision 313: published by Pat Heideman
 Revision 314: published
 Revision 315: published
 Revision 316: published by Quadrowin
 Revision 317: published
 Revision 318: published by tjaden
 Revision 319: published
 Revision 320: published
 Revision 321: published by xkliber
 Revision 322: published
 Revision 323: published
 Revision 324: published
 Revision 325: published by scott
 Revision 326: published by Todd Anglin
 Revision 327: published
 Revision 328: published by Joseph Scott
 Revision 329: published by Yavanosta
 Revision 330: published by jeremy
 Revision 331: published
 Revision 332: published
 Revision 333: published
 Revision 334: published
 Revision 335: published by Zdenek
 Revision 336: published by Oleg
 Revision 337: published by Oleg
 Revision 338: published by weight loss
 Revision 339: published by Andrew
 Revision 340: published by Andrew
 Revision 341: published
 Revision 342: published
 Revision 343: published
 Revision 344: published by haeki
 Revision 345: published by Elliskin anti aging
 Revision 346: published
 Revision 347: published
 Revision 348: published
 Revision 349: published by Alf and last updated
 Revision 350: published by klaasman
 Revision 351: published by id vs tag:first
 Revision 352: published by id vs tag:first 2
 Revision 353: published
 Revision 354: published by Hemin
 Revision 356: published
 Revision 357: published
 Revision 358: published by Dennis
 Revision 359: published
 Revision 360: published by Sven
 Revision 361: published
 Revision 362: published
 Revision 363: published by Dennis
 Revision 364: published
 Revision 365: published by Oleg
 Revision 366: published by DJM
 Revision 367: published by Oleg
 Revision 368: published
 Revision 369: published by tester123
 Revision 371: published
 Revision 372: published
 Revision 373: published
 Revision 374: published
 Revision 375: published
 Revision 376: published
 Revision 377: published
 Revision 379: published
 Revision 380: published by Oleg
 Revision 382: published
 Revision 383: published by Johb
 Revision 384: published by Joseph Gabriel
 Revision 385: published by Cole Geissinger
 Revision 386: published
 Revision 387: published
 Revision 388: published
 Revision 389: published
 Revision 391: published
 Revision 392: published
 Revision 393: published by Adam Shiervani
 Revision 394: published by Rut
 Revision 396: published by testtest
 Revision 397: published by Jeff Rousseau
 Revision 398: published
 Revision 399: published
 Revision 400: published
 Revision 401: published by Edward
 Revision 402: published by Edward
 Revision 403: published by Deavy
 Revision 404: published by Eugene
 Revision 405: published
 Revision 406: published by Ratione ab inventore fugit eos itaque deleniti porro molestias lorem repellendus
 Revision 407: published by david
 Revision 408: published
 Revision 409: published by Jelle De Loecker
 Revision 410: published by Nik
 Revision 411: published by Nik
 Revision 412: published by Nik
 Revision 413: published by Nik
 Revision 414: published
 Revision 415: published by pleazo2008
 Revision 416: published by pleazo2008
 Revision 417: published by pleazo2008
 Revision 418: published
 Revision 419: published
 Revision 420: published by fncallvsasdqwe
 Revision 421: published by logan
 Revision 422: published by Dima
 Revision 424: published
 Revision 425: published by Paddy
 Revision 426: published by Aaron M.
 Revision 427: published by Aaron M.
 Revision 428: published by John Nguyen
 Revision 429: published
 Revision 430: published
 Revision 431: published
 Revision 433: published by Mateusz Krzeszowiak
 Revision 434: published
 Revision 435: published by John
 Revision 436: published by John
 Revision 437: published by Wayne
 Revision 438: published by Mateusz Krzeszowiak
 Revision 439: published by Mateusz Krzeszowiak
 Revision 440: published by Mateusz Krzeszowiak
 Revision 441: published by etoxin
 Revision 449: published by firoz
 Revision 450: published
 Revision 451: published
0 comments
Comment form temporarily disabled.