jQuery :has vs .has() vs .parent()

JavaScript performance comparison

Test case created

Info

Based on http://jsperf.com/jquery-has-vs-has

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
<code>Foo bar<br>baz</code>
<code>Foo bar baz</code>
 

Preparation code output

Foo bar
baz
Foo bar baz Foo bar
baz
Foo bar baz Foo bar
baz
Foo bar baz Foo bar
baz
Foo bar baz Foo bar
baz
Foo bar baz Foo bar
baz
Foo bar baz Foo bar
baz
Foo bar baz Foo bar
baz
Foo bar baz

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
:has selector
$('code:has(br)');
pending…
.has() method
$('code').has('br');
pending…
.parent()
$('code br').parent();
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