parent() vs parentNode simple

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code

<div id="outer" class="myClass" data-id="23">
<div>
<span class="c-tab" onclick="switchWhpTab(this)"><span class="c-tab-a">All</span><span class="c-tab-x" onclick="$('#chattabs').html('');">✖</span></span>
<span class="c-tab" onclick="switchWhpTab(this)" data-id="1"><span class="c-tab-n">Hi</span><span class="c-tab-x" onclick="closeWhpTab(event,this)">✖</span></span>
<span class="c-tab" onclick="switchWhpTab(this)" data-id="2"><span class="c-tab-n">Hit</span><span class="c-tab-x" onclick="closeWhpTab(event,this)">✖</span></span>
<span class="c-tab" onclick="switchWhpTab(this)" data-id="3"><span class="c-tab-n">Hite</span><span class="c-tab-x" onclick="closeWhpTab(event,this)">✖</span></span>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    

Preparation code output

<div id="outer" class="myClass" data-id="23"> <div> <span class="c-tab" onclick="switchWhpTab(this)"><span class="c-tab-a">All</span><span class="c-tab-x" onclick="$('#chattabs').html('');">✖</span></span> <span class="c-tab" onclick="switchWhpTab(this)" data-id="1"><span class="c-tab-n">Hi</span><span class="c-tab-x" onclick="closeWhpTab(event,this)">✖</span></span> <span class="c-tab" onclick="switchWhpTab(this)" data-id="2"><span class="c-tab-n">Hit</span><span class="c-tab-x" onclick="closeWhpTab(event,this)">✖</span></span> <span class="c-tab" onclick="switchWhpTab(this)" data-id="3"><span class="c-tab-n">Hite</span><span class="c-tab-x" onclick="closeWhpTab(event,this)">✖</span></span> </div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
better parent()
$(function() {
$('.c-tab-n').each(function(){
alert($(this.parentNode).attr('data-id'));    
});
});
pending…
parent()
$(function() {
$('.c-tab-n').each(function(){
alert($(this).parent().attr('data-id'));    
});
});
pending…
parentNode
$(function() {
$('.c-tab-n').each(function(){
alert(this.parentNode.getAttribute("data-id"));    
});
});
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.

0 Comments

All✖ Hi✖ Hit✖ Hite✖