jquery set haspopup for wp

JavaScript performance comparison

Revision 3 of this test case created

Info

jQuery change to open WordPress menus on first tap, simulating hover on touch devices such as Windows 8, WP8, etc.

To emulate menu hover behavior on touch devices, two attributes need to be set. This tests if jQuery is faster: a) When using more specific or more generic selectors and b) If it is faster to execute both commands separately or to chain them.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="menu">
<ul>
  <li ><a href="http://www.example.com/" title="Home">Home</a></li>
  <li class="page_item"><a href="http://www.example.com/page1/">Page 1</a><!-- Attr expected here -->
    <ul class='children'>
      <li class="page_item"><a href="http://www.example.com/page1/page11/">Page 11</a></li>
      <li class="page_item"><a href="http://www.example.com/page1/page12/">Page 12</a><!-- Attr expected here -->
        <ul class='children'>
          <li class="page_item"><a href="http://www.example.com/page121/page121/">Page 121</a></li>
          <li class="page_item"><a href="http://www.example.com/page122/page122/">Page 122</a></li>
        </ul>
      </li>
    </ul>
  </li>
  <li class="page_item"><a href="http://www.example.com/page2/">Page2</a></li>
  <li class="page_item current_page_item"><a href="http://www.example.com/page3/">Page3</a></li>
</ul>
</div>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
ul > li.page_item
$("ul > li.page_item").has("ul").children("a").attr("aria-haspopup","true");
pending…
li.page_item
$("li.page_item").has("ul").children("a").attr("aria-haspopup","true");
pending…
.page_item
$(".page_item").has("ul").children("a").attr("aria-haspopup","true");
pending…
.page_item:has(ul) > a
$(".page_item:has(ul) > a").attr("aria-haspopup","true");
pending…
.menu li:has(ul) > a
$(".menu li:has(ul) > a").attr("aria-haspopup","true");
pending…
.menu .page_item
$(".menu .page_item").has("ul").children("a").attr("aria-haspopup","true");
pending…
.menu li
$(".menu li").has("ul").children("a").attr("aria-haspopup","true");
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:

0 comments

Add a comment