jquery-element-class (v2)

Revision 2 of this benchmark created on


Description

Determine whether or not prefacing a class-name with an element name achieves any performance boost with jQuery selectors.

Hypothesis: like in CSS, adding an element name to the class name will not provide any performance boost, because selectors are evaluated right-to-left. Also, pseudo-selectors are slow.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div class="visible">
  <p>
    Shown
  </p>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
Selector Plus Class
$("div.visible").hide();
ready
Class Only
$(".visible").hide();
ready
Pseudo Class
$(".visible:visible").hide();
ready
.is(':visible')
var d = $(".visible");

if (d.is(":visible")) {
  d.hide();
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Joshua Cody on
  • Revision 2: published on